Batch insert filename in textpath script blocks Illustrator

Hello world!

First: I'm not a programmer. Just play with the code and trying to make it work for a specific task:

Here is a script for the purpose of inserting a text specifying the file name in more than 600 files pdf. This is supposed to work on all the files in a selected folder.

The problem: Illustrator crashes.

A first test code worked but after a few files published Illustrator crashed, so I tried to introduce a delay after each registered in order to slow down the batch.

$.setTimeout (function () {sourceDoc.close (SaveOptions.SAVECHANGES)}, 1000);

Unfortunately, I have not saved the work (work almost ) first to test the code.

No idea what to do next. The code works if I remove this line: sourceDoc.close (SaveOptions.SAVECHANGES);

Here's the complete script:

var destFolder, sourceFolder, files, fileType, sourceDoc, layers, writeText, finLabel;

// Select the source folder.
sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PNG', '~' );

// If a valid folder is selected
if ( sourceFolder != null )
{
files = new Array();
fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', '*.pdf' );

// Get all files matching the pattern
files = sourceFolder.getFiles( fileType );

if ( files.length > 0 )
for ( i = 0; i < files.length; i++ )
{
    sourceDoc = app.open(files[i]); // returns the document object
    layers = unlock();
    writeText = getFilename();
    finLabel = remText();
    sourceDoc.close(SaveOptions.SAVECHANGES);   //if save command line is deleted the code works   WTF???
    $.setTimeout(function () {sourceDoc.close(SaveOptions.SAVECHANGES)}, 1000); // still crashes using delay ...
}
//alert( 'Files are saved as PNG in ' + destFolder );

else
{
alert( 'No matching files found' );
}
}

function unlock()
{
   //get the total number of layers in the active document
doc = app.activeDocument;
var totalLayers = doc.layers.length;

//looping on layers to create one artboard per layer
for ( var i = 0 ; i < totalLayers ; i++){
    
    var currentLayer = doc.layers[i];
    
    //We don't want to deal with hidden layers
    if(currentLayer.visible == false) continue;
    
    //Unlock the layer if needed
    currentLayer.locked = false;

}
    }

function getFilename()
{
// Write text
var pointTextRef = app.activeDocument.textFrames.add();
pointTextRef.contents = app.activeDocument.name + "\n" + "YBS";
pointTextRef.top = 0;
pointTextRef.left = 0;
app.activeDocument.textFrames[0].textRange.characterAttributes.textFont=app.textFonts[31];
    
    }

function remText()
{
// This works for search and replace :))))))

    var active_doc = app.activeDocument;  
      
    var search_string = /_Template.pdf/gi; // g for global search, remove i to make a case sensitive search  
    var replace_string = '';  
      
    var text_frames = active_doc.textFrames;  
      
    if (text_frames.length > 0)  
    {  
        for (var i = 0 ; i < text_frames.length; i++)  
          {  
              var this_text_frame = text_frames[i];  
               var new_string = this_text_frame.contents.replace(search_string, replace_string);  
                 
               if (new_string != this_text_frame.contents)  
                   {  
                        this_text_frame.contents = new_string;  
                   }  
          }  
    }      
 }

Any ideas on what makes Illustrator plant them?

Note: The application crashes after opening the first file.

Thanks for helping out!

the timeout function, that you added is not supported by extendScript,

your script works well with a few files tested, the problem might be on the large number of files, 600 seems a little too much for illustrator. Re start illustrator, do a little at a time, enough as to not illustrator crash, re - start illustrator... Rinse, repeat.

Tags: Illustrator

Similar Questions

  • Photoshop layer redesign, rename the script for Illustrator

    The Photoshop scripting guru Paul R more to RetouchPro has created a really cool to rename script and layers of selected Photoshop batch numbers. I did find something similar on the side of the Illustrator.

    He gave his permission for me to post it here in hopes that some Illustrator scripting genius could come up with a similar script for Illustrator. It would be terribly difficult to convert into something that could use Illustrator?

    http://www.mediafire.com/file/g7usr73u0236p0a/rename _ & _Renumber_Selected_Layers.jsx

    http://www.mediafire.com/file/dbah74x13bsa74c/rename _ & _Renumber_Selected_Layers.jsx.zip

    rename-layers.png

    Hola Julio, I updated the script to rename the sublayers or visible layers and also fixed the color

    #target illustrator
    
    main();
    function main(){
        if(!documents.length) return;
        //var allLayers = app.activeDocument.layers;
        var win = new Window( 'dialog', '' );
        g = win.graphics;
        //  var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]); // CS5
        var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.50, 0.50, 0.50, 1]); // CS6
        g.backgroundColor = myBrush;
        win.orientation='stack';
        win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
        win.g1 = win.p1.add('group');
        win.g1.orientation = "row";
        win.title = win.g1.add('statictext',undefined,'Rename Visible Layers or Sublayers');
        win.title.alignment="fill";
        var g = win.title.graphics;
        g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
        win.g5 =win.p1.add('group');
        win.g5.orientation = "column";
        win.g5.alignChildren='left';
        win.g5.spacing=10;
        win.g5.st1 = win.g5.add('statictext',undefined,'New layer name');
        win.g5.et1 = win.g5.add('edittext');
        win.g5.et1.preferredSize=[250,20];
        win.g10 =win.p1.add('group');
        win.g10.orientation = "row";
        win.g10.alignment='fill';
        win.g10.spacing=10;
        win.g10.st1 = win.g10.add('statictext',undefined,'Serial Number');
        win.g10.et1 = win.g10.add('edittext',undefined,'1');
        win.g10.et1.preferredSize=[50,20];
        win.g10.et1.onChanging = function() {
          if (this.text.match(/[^\-\.\d]/)) {
            this.text = this.text.replace(/[^\-\.\d]/g, '');
          }
        };
        win.g10.st1 = win.g10.add('statictext',undefined,'Length');
        var nums=[2,3,4,5];
        win.g10.dl1 = win.g10.add('dropdownlist',undefined,nums);
        win.g10.dl1.selection=0;
        win.g15 =win.p1.add('group');
        win.g15.orientation = "row";
        win.g15.alignment='fill';
        win.g15.cb1 = win.g15.add('checkbox',undefined,'Reverse layer order');
        win.g15.cb2 = win.g15.add('checkbox',undefined,'Rename Sublayers Only');
        win.g100 =win.p1.add('group');
        win.g100.orientation = "row";
        win.g100.alignment='center';
        win.g100.spacing=10;
        win.g100.bu1 = win.g100.add('button',undefined,'Rename');
        win.g100.bu1.preferredSize=[120,30];
        win.g100.bu2 = win.g100.add('button',undefined,'Cancel');
        win.g100.bu2.preferredSize=[120,30];
        win.g100.bu1.onClick=function(){
            if(win.g5.et1.text == ''){
                alert("No layer name has been entered!");
                return;
            }
            win.close(0);
    
            var sublayersOnly = win.g15.cb2.value;
            var visibleLayers = [];
            getVisibleLayers (app.activeDocument, visibleLayers, sublayersOnly);
    
            if(win.g15.cb1.value) visibleLayers.reverse();
    
            for(b=0; b		   
  • batch file to run the script to report

    Hello

    How to create a batch file to call my script essbase report.

    Thank you!

    Hello

    you create a MaxL script that calls the report script. When it does not, you create a batch file that launches the MaxL script.

    MaxL example: export sample.basic database using fichier_journal '' $ARBORPATH/App/Sample/Basic/asym.rep' ' of data_file ' home/month2.rpt ";

    The batch file called essmsh.

    Kind regards

    Philip Hulsebosch

  • TimesTen jdbc batch insert a bug with CallableStatement. Batch insert parameters and inserts dublicates first parameter n times with CallableStatement.

    Hello, below batch insert has a problem with CallableStatement. But PreparedStatement(commented lines) there is no problem. Batch insert parameters and inserts dublicates first parameter n times with CallableStatement. Maybe there is a bug in the driver jdbc TimesTen (ttjdbc7.jar) or some other problem. I use TimesTen version 11.2.2.5.0 and Java 7u51.

    Help, please!

    ...
    //PreparedStatement statement = null;
    CallableStatement statement = null;
    //String sql = "INSERT INTO address_book(id, user_id, phone_number) VALUES (seq_id.nextval, ?, ?)";
    String sql = "{call add_phone_number(?, ?)}";
    try {
        //statement = getConnection().prepareStatement(sql);
        statement = getConnection().prepareCall(sql);
        for (String phoneNumber : list) {
            statement.setLong(1, userId);
            statement.setString(2, phoneNumber);
            statement.addBatch();
        }
        statement.executeBatch();
    } finally {
        if (statement != null) {
            statement.close();
        }
    }
    ...
    
    
    
    

    It is a known problem. We expect to have a fix in a future version, but there is currently no ETA that I can share with you. I recommend that you connect a SR with support so that we can follow the fact that this problem affects you.

    Chris

  • When I try to batch photos to resize in Scripts &gt; Image Processor function, an error message that says: "comand"Pen"is not available. What can I do to fix this?

    When I try to batch photos to resize in Scripts > Image Processor function, an error message that says: "comand"Pen"is not available. What can I do to fix this?

    Yes Adobe tile action fails with the error when he didn't is not the active selection. Note that the Cut Out, built-in frame and thumbnail (selection) after their name. These actions require an active selection to the selected mobile dotted lines before using the action.  Action seeks to soften the selection that were provided to you.  There was no selection, so there is nothing to be flag.

    In addition, the step of the pen in the action of the tile is an interactive step on its dialog box is.  An interactive action defeat as the design of the Image Processor script commands.  Isn't interactivity in a batch.

  • Acrobat 11 Pro Installer get hung up when he made "to"install script blocks... »

    I have a 2008 15 "Unibody Macbook Pro with replaceable battery life of five hours.  It has 8 GS of RAM and it is initialized under Mountain Lion.  The Acrobat Pro 11 Installer get hung up when it gets to "install script blocks...". "It never ends installation.  I tried after starting in safe mode and then start Mode once again used to start the mode.  I have had no success.  The Acrobat Pro 11 installer works fine when it is installed on my Mac Pro 2007 32-bit office, started under Leo.  I have to try something fancy with the command line, using the Terminal application?  I'm puzzled.

    Greetings, Rave and Sabian.

    I solved the problem installing Acrobat Pro 11 without reformatting the internal hard drive of my Macbook Pro.  I reinstalled Mountain Lion on top of the existing installation of Mountain Lion.

    I have reinstalled Lion on my ' 07 32 bit Mac Pro, a month ago, and it is resolved many issues.  So, re-install on top existing Cougar Mountain Lion facility was the difficulty of obtaining the Acrobat Pro 11 install to complete and eliminate also some other system bugs I had.

    After using Acrobat Pro 11 on my Mac Pro, for more than a week, I must say that it is a huge improvement on Acrobat 9 Pro.  I like to have the tools and commenting on the tabs above to the right of the window and using the top menu much less.  It scrolls PDF pages and comments two separate activities, which allows the refresh of the screen to be much faster and better.

    Acrobat Pro 11 is a great version!

  • Code of Script of Illustrator to remove selected items

    Hello, I have a script of Illustrator to cross certain functions and after it runs, there are selected items that I need to remove. I can't understand the simple script to delete the selected items. I tried

    var docSelected = app.activeDocument.selection;

    docSelected.selected.remove ();

    but in vain. Help, please. I would be very happy the tips and suggestions that I just need to know how to do so that the script to remove the selected items. Thank you very much!

    Another way...

    var docSelected = app.activeDocument.selection;
    for (j=0; j		   
  • How to use a table defined in the main Script block in an InlineCode Block of a DataGridColumn ComboBox itemRenderer?

    Hello

    How can I use a table defined in the main Script block in an InlineCode Block of a DataGridColumn ComboBox itemRenderer?

    Thanks for any help!

    Martin West

    I hope my problem with the Code:

    < fx:Script >

                <! [CDATA]

    private var myArrayOut: Array =new Array (' one of ','out two', "three out");

    < / fx:Script >

    ...

    DataGrid...
    < mx:DataGridColumn headerText = "MyColumn" dataField = "MyColumn" rendererIsEditor = "true".
    < mx:itemRenderer >
    < fx:Component >
    < mx:ComboBox creationComplete = "init ()" >
    < fx:Script >
    <! [CDATA]
    private var myArrayIn: Array = new Array ('one', 'two', 'three');

    private function init (): void {}

    this.dataProvider = myArrayIn; / / How can I use myArrayOut here?
    }
    []] >
    < / fx:Script >
    < / mx:ComboBox >
    < / fx:Component >
    < / mx:itemRenderer >
    < / mx:DataGridColumn >

    Hello

    outerDocument is a link to external data and functions.

    If you need

    outerDocument.myArrayOut.

  • ??? Simple SCRIPT of Illustrator necessary?

    Greetings.

    I was wondering if anyone knew a well-known script there that for Illustrator that could automate this process (see attachment).

    Much appreciated!

    Screen Shot 2016-02-02 at 10.42.46 AM.png

    The CADtools plugin has a feature of numbering.

    You might also: first select

    Type > threaded text > do

    Use Excel to generate the numbers and a return delimiter

    Copy and paste into the text block

  • Change the source file of the insert text with a script

    I'm looking for a way to replace existing-insert text in a document with the contents of another file (by reference), using scripts. I have a document c:\referer.fm, in which there is an insert text which the source file is: c:\A.fm

    I also have c:\B.fm, and now I want to change referer.fm so that is no longer the overlay of text contains the text of A.fm, but the B.fm.

    I tried this:

    var doc is app. ActiveDoc;

    var textinset is doc. FirstTiInDoc;

    var pathtosource is textinset. TiFile;

    pathtosource = "c:\B.fm";

    textinset. UpdateTextInset();

    But it does not work. I guess that the "pathtosource" parameter can be done this way. If someone knows a way to do it, I would greatly appreciate your help!

    David

    Hello David,.

    You do not manipulate the text overlay, but a copy of the file in the text box. Your "pathtosource" parameter is a local copy of the property that you read from the actual text insert.

    Try this code instead:

    var doc is app. ActiveDoc;

    var textinset is doc. FirstTiInDoc;

    textinset. TiFile "c:\\B.fm".

    Note that the backslash must be escaped with the backslash to make it work in a JavaScript string. To make your script Fail-Safe, test the name of file textinset before changing. You do not have the textinset that you expect to have, as might also be INSET text on master pages and reference. All inserts text are in a single linked list.

    Also, update the text tagging along after that changing the path may not always work, as compared to FM, last changed the file date text inset with the last time that the textinset has been updated. To force the FM to update the textinset, you must include the following line of code after changing the filename text inset:

    textinset. LastUpdate = 0;

    Then, you can call the UpdateTextInset() method and it will work.

    Good luck.

    Jang

  • BATCH inserts

    Hello
    9i, a batch is running to isert 25000 lines in a table.
    Of course, you can not see them before final validation.
    Is it possible to see if it is going and how many lines is already inserted?

    Thank you.

    Looking for v$ session_longops. I think that will tell you various operations that run for more than 6 seconds (in absolute time).
    http://docs.Oracle.com/CD/B10501_01/server.920/a96536/ch3175.htm#1123208

    Another good note to the link below:
    http://www.gplivna.EU/papers/v $session_longops.htm

    Concerning
    Girish Sharma

  • How to insert data into the initialization blocks

    I want to connect the user which connect to the obiee system. in the initialization, user blocks, we can get, but how to insert the date and user in the database is it in any way. Thanks in advance.

    The connection id is stored in the system USER session variable. You can use it to insert into the database in the initialization block.

    INSERT INTO tablename (username, date) values (': USER ', sysdate);

  • call a batch file in the sql scripts

    Hi friends,
    I'm looking for a way to call any batch file in sql scripts. I avoid using the DBMS_SCHEDULER package because my application server and database server are deparaments.
    I use the sql script using the server.plz application.


    Ah, I see. Of course, this explains everything.

    Now to be serious: there is no way to run a batch SQL script. The Tools that present SQL statements to the database are often able to do; host in SQL * Plus may issue commands to the OS, the host of builtin forms is it too and with dbms_scheduler , you can run a shell script on the database server.

    So depending on the tools you use, there are several ways to run the OS commands. So far you didn't tell us what you want to do with what tools in the version you want to do. So to only answer is: it is not possible. You cannot run a simple SQL command script.

    see you soon

  • How to make the button script in Illustrator?

    Dear all,

    Recently, I always use Illustrator 2 free, script text are: "joinTextFrames" & "divideTextFrame".

    but I lost a lot of step to do

    for example, click: 1. Select text-> 2. File-> 3. Script-> 4. Another script-> load a script

    Fastest way-> Ctrl + F12-> load a script

    But now I want to do is the key 2 'joinTextFrames' & 'divideTextFrame '. The same way "mode button" in stock for faster work.

    How to make or solution to make? I really need it for my work.

    Thanks for your help.

    Save your scripts folder in the scripts, like that they'll show in the file-> Scripts Menu. Then, save the two actions to run each script, each gives a shortcut key (i.e. & F3 F2) or run the Mode button if you want to.

    Note that you need to re - register the action every time that you restart illustrator.

  • Batch files IDCS3 XML export script

    Someone at - it a script that he would share for batch export XML from files IDCS3? I don't know anything about scripts, so I don't know how to write one myself. I also searched around and found nothing. I'd appreciate any help with this person can offer.

    Thank you

    Janine

    Load a file that has an XML in it, all you want in the export XML dialog box, export this file. These are now the default export settings. Then run script of Shonky or mine.

    Peter

Maybe you are looking for

  • export library

    You can export a complete library in pictures

  • Another device is using my IP address

    Today morning when I switched on my macbook, I received a message pop - up-"another device on the network use the IP address of your computer. This means that my computer is hacked? Or has nothing to do with the common wi - fi network, I use?

  • Market with power supply is not possible on the Satellite M60-167

    Hello I'm sorry for my English saw. I have a problem with my Satellite M60-167. When I have connected the laptop with power supply and press the 'Power', then does'nt start Notepad.When I use only the battery and push a lot of times the "Power Button

  • Photos & music

    Vista is capable of burning pictures with background music? Or I need different software and please suggest a program that I can download for free or at low cost; It's a good program. Thanks Stephen06

  • Upgrade Windows 10 on my development Manchine

    What happens if I upgrade Windows 10 on my development Manchine? I am a PHP programmer and have installed many programs and configured my PC up to a point where it works very well. What happens to my programs after the upgrade? I can guess the natura