9 Replies Latest reply on Aug 19, 2015 7:11 AM by Silly-V

    Create Id:s on all types of objects

    Elmnas

      I have a long process to walk through a couple weeks....

       

       

      I will create an text export script and an text import script.

      I am new beginner I have been written many scripts in vba, for (Excel and Word).

      and just simply once in Indesign..

       

       

      What do you think about this idea?

       

       

      Create an list of all objects in a document (the ID:s)

      then try to make a function that export the  text and ID into a line in a textfile.

       

       

      then when I create an import script if "ID=1" exists then take the "ID=1" in the textfile and replace.

       

       

      have you got any suggestions?

       

       

      Thank you in advance.

       

       

      Best regards

       

       

      Daniel.

        • 1. Re: Create Id:s on all types of objects
          Silly-V Adobe Community Professional

          That sounds reasonable, you can use the notes or names of art objects, as well as the mysterious Illustrator tags or even the URL (accessed by pageItem.uRL, not URL like OMV says).

          • 2. Re: Create Id:s on all types of objects
            Elmnas Level 1

            How to you create a note on every object?

            • 3. Re: Create Id:s on all types of objects
              Silly-V Adobe Community Professional

              Through the UI, you use the Attributes panel and type in your note in the note text area. With script, it's as easy as pageItem.note = "blah";

              If you want to numerize your whole document, for example, you can do something like:
              for(var i=0; i<app.activeDocument.pageItems.length; i++){

                   var item = app.activeDocument.pageItems[i];

                   item.note = "ID: " + (i + 1);

              };

               

              all of your art objects will have a note that says "ID: 1" , "ID: 2", etc.

              You can also do this with the "name" property and see your results better , as they will be displayed in the layers panel.

              However, pageItems encompass all of the different items in the document, which includes paths inside a compound path, which are not seen in the layers panel because they are inside the compound path.

              • 4. Re: Create Id:s on all types of objects
                Qwertyfly... Level 4

                if you are not closing the document and you don't need the ID's later you can just add a new item to the object.

                these will be accessible until the document is closed. and will be lost on close. ie not there when the file is reopened even if you saved it.

                 

                var doc = app.activeDocument;  
                var sel = doc.selection;
                
                
                for(var i=0;i<sel.length;i++){
                        sel[i].my_new_ID = "ID"+i;
                }
                
                • 5. Re: Create Id:s on all types of objects
                  CarlosCanto Adobe Community Professional & MVP

                  great idea, only after reading the property from a selected object, the others turn undefined, I added it to pageItems instead and they persisted...now we need to find a good use for it.

                  • 6. Re: Create Id:s on all types of objects
                    Qwertyfly... Level 4

                    ok, may not be ideal.

                    if I run:

                    var item = app.activeDocument.pageItems;    
                      
                    for(var i=0;i<item.length;i++){  
                            item[i].my_new_ID = "ID" + i ;  
                    } 
                    

                    then run this:

                    for(var i=0;i<item.length;i++){  
                            alert(item[i].my_new_ID);  
                    } 
                    

                    then I get the expected

                     

                    but if I run:

                    var item = app.activeDocument.pageItems;    
                      
                    for(var i=0;i<item.length;i++){  
                            item[i].my_new_ID = "ID" + i ;  
                    } 
                    

                    followed by:

                    var item = app.activeDocument.pageItems;    
                    
                    
                    for(var i=0;i<item.length;i++){  
                            alert(item[i].my_new_ID);  
                    } 
                    

                    then a random few items do not retain the ID and I can't see what is special about those items.

                     

                    strange...

                    I may have to look into this a bit deeper when I have time.

                    • 7. Re: Create Id:s on all types of objects
                      CarlosCanto Adobe Community Professional & MVP

                      strange...like most other non-working stuff

                      • 8. Re: Create Id:s on all types of objects
                        Elmnas Level 1

                        Thank you in advance mate,

                         

                        I am running Illustrator on Windows, I have illustrator cc and illustrator cs4,

                        extended toolkit 4 and extended toolkit cc,

                        Its so annoying the toolkit doesn't recognize illustrator.

                        each time I run a script I get errors.

                        • 9. Re: Create Id:s on all types of objects
                          Silly-V Adobe Community Professional

                          While I do assume OP wanted to actually have the IDs persist (for the import script), I think your experiment definitely tells us something about the inner workings (or mis-workings) of the JS execution in ExtendScript. Could this be tied to the random MRAP and PARM errors we experience in iteration of color swatches and pageItems?

                           

                          I hypothesize this because, it looks like when you are using the same variable name when instantiating the app.activeDocument.pageItems, that's what typically we do when using functions to accomplish tasks - say, you wrapped the code in a function and called it multiple times. I think during those scenarios I get the issue of corrupted properties on my pageItems or color swatches. It also "sort-of" makes sense that such errors for me almost never start at the fresh beginning of running a script (fresh AI restart, first script run, first loop of script) and then the chance of those errors grows and grows as scripts are ran more and more. william states that toward the end of the day, MRAP errors keep increasing until they get completely overwhelming.