10 Replies Latest reply on Jul 1, 2015 9:21 AM by fredsky2014

    how to place a copy of a librairie item with a script?

    fredsky2014 Level 1

      i've created a librairie with 1 graphic.

      i can place this item as a embeded copy (only option available in cc 2014), or as a link (new with cc 2015)- just right click and choose the place in context menu.

       

      now, how can i do this from script?

       

      with this little skeleton from from the reference PDF i get access to the item from librairie in current document = so should be easy to place it as copy ...

       

       

      if ( app.documents.length > 0 ) {

      var fileReferences = new Array();

      var sourceDoc = app.activeDocument;

      var sourceName =sourceDoc.name;

       

       

      for ( i = 0; i < sourceDoc.pageItems.length; i++ ) {

      artItem = sourceDoc.pageItems[i];

       

          switch ( artItem.typename ) {

              case "PlacedItem":

              fileReferences.push( artItem.file.fsName );

             

             

              break;

      }

      }

       

      fred

        • 1. Re: how to place a copy of a librairie item with a script?
          Qwertyfly... Level 4

          not sure the above is what you are after.

           

          if you create an action and while recording drag your graphic from the library to your document.

          the action will contain the local path to the graphic.

           

          you could place the graphic with javascript using that path.

          or just use the action

           

          li.JPG

          • 2. Re: how to place a copy of a librairie item with a script?
            fredsky2014 Level 1

            hello!

            even in action the "place as copy" doesn't appears. only the "place as link" will be show in the action palette.

            seem that is a "new rushed" feature that is not present in any form of script/macro

             

            fred

            • 3. Re: how to place a copy of a librairie item with a script?
              Qwertyfly... Level 4

              record action to get local file location.

              add that to the code below.

              remember replace "\" with "/"

               

              var myfile = File("C:/Users/tristan/AppData/Roaming/Adobe/Creative Cloud Libraries/LIBS/70DE407249FFD926992016B8_AdobeID/creative_cloud/dcx/2FB37286-9657-4C80-B2DA-00D4F3C215EA/components/3ced2d9e-4390-4971-b0f5-6d6682111925.png");
              var placed = app.activeDocument.placedItems.add();
              placed.file = myfile;
              placed.position = [0,0];
              placed.embed();
              
              • 4. Re: how to place a copy of a librairie item with a script?
                fredsky2014 Level 1

                perhaps i'm not clear, but this script is about the same i explained first.

                however this DOES NOT make a copy, it convert a link to embed. and this is a buggy feature of illustrator, because when it does so, it will convert anything to graph & outlines.

                so a text will become a outline (Loosing text editability), and svg interactivity is lost.

                this is how people where working with symbols, before cc 2015 with librairies.

                 

                so what i need is something to :

                select a linked object (in fact all same reference object), find it into the libraries (easy to do, see first script), and replace it by the "place a COPY". this now is a perfect file, all copy are updated correctly and in place.

                 

                fred

                • 5. Re: how to place a copy of a librairie item with a script?
                  Qwertyfly... Level 4

                  I don't get text becoming outlined,

                  but I do get a dumb amount of clipping paths.

                  I hate the over use of unnecessary clipping paths.

                   

                  I'm still not sure what you really want to do.

                  But this may be getting closer...

                   

                  start by dragging your desired library Items to your document.

                  this places them all as links.

                  once you are happy, run this script.

                  it will replace each linked library item with a copy.

                   

                  if ( app.documents.length > 0 ) {
                      var sourceDoc = app.activeDocument, artItem, myAsset, pos = [];
                      sourceDoc.selection = null;
                      for (var i = sourceDoc.placedItems.length-1; i > -1; i-- ) {
                          artItem = sourceDoc.placedItems[i];
                          pos = [artItem.left,artItem.top];
                          myAsset = File(artItem.file.fsName);
                          app.openCloudLibraryAssetForEditing(myAsset,myAsset);
                          app.executeMenuCommand ('selectall');  
                          app.executeMenuCommand ('copy');  
                          app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                          sourceDoc.activate();
                          app.executeMenuCommand ('paste'); 
                          app.executeMenuCommand ('group'); 
                          sourceDoc.selection[0].position = pos;
                          artItem.remove();
                      }
                  }
                  
                  • 6. Re: how to place a copy of a librairie item with a script?
                    fredsky2014 Level 1

                    yesssssssssssssss!

                    i don't know how you have access to hidden scripting function of cc 2015 like "openCloudLibraryAssetForEditing", but it does work - almost- perfectly. there are some quirks, i've to make many tests to find exactly what.

                     

                    so now everybody / web designer has AT LEAST a great way of :

                    - sharing items on the cloud, on project and on pages (this is a improved version of Symbols at last)

                    - preserve ALL attributes inside this improved symbol (like text and svg links)

                    - i don't get why it takes so long to Adobe to create a tool that have the feature of "master" and "children", so that when i create a menu for a web, ALL my pages are automatically updated each time i change the menu - AND nothing is converted or changed to outlines.

                    => a true master/children copy damn it! it was time!

                     

                    fred

                    • 7. Re: how to place a copy of a librairie item with a script?
                      Qwertyfly... Level 4

                      script with the ESTK.

                      Object Model Viewer is your friend.

                       

                      glad I could help you out,

                      I had not realized till I was playing with this that CC2015 decided it was better to link by default.

                      there should be an option to set the default when dragged and dropped to document

                      • 8. Re: how to place a copy of a librairie item with a script?
                        fredsky2014 Level 1

                        "there should be an option to set the default when dragged and dropped to document" this is not needed.

                        because the quirk in the way they've implemented is :

                        - either to "place links" everywhere you place a library item=> the only way that all you links will be updated once you modify the master item in library... / but again links does not preserve text/svg interactivity and others...

                        -either you "place a copy" of the library item, but all notions of update are gone... so useless .

                         

                        so the only good way to get both features is to :

                        - create a document with links everywhere. you can also create/use links to other librairies items inside the same item (recursive). EXTREMELY easy and powerfull. you can store graphics, colors, text styles, text => any time you modify/edit any library items they will updated on all related AI pages

                        - save this page as it, do NOT save the version with copy!!!

                        - use you script to convert all links to copy => now we got access back to text and svg interactivity, since basically you edit each library item, selectall+copy & replace the corresponding link.  export this is other format for web or pdf...

                        • 9. Re: how to place a copy of a librairie item with a script?
                          Qwertyfly... Level 4

                          My main use for items in the cloud library is for element I use over and over again.

                          These do not change, and do not need to be dynamic.

                          in CC2014 I would drag a graphic to where I want it and move on.

                          Now I Must right click, chose place Copy, then drag the graphic to where I want it.

                          this takes twice as long and is driving me crazy.

                          if I forget to do this and drag in a link then it is not available when the printer opens the document due to it being a link.

                           

                          I would like the option of making the default for graphics dragged from the library panel to be placed as a copy!

                          • 10. Re: how to place a copy of a librairie item with a script?
                            fredsky2014 Level 1

                            here is my current working and improved code. it does automatically convert ALL linked items into a copy, with same position and size.

                            it also take care of missing links.

                            but if there is NONE placed items, i get an error...

                             

                            function convertLinksLibrariesToCopies()
                            {
                                var sourceDoc = app.activeDocument;
                                var artItem;
                                var myAsset;
                                var pos = [];
                                var fileName;
                            
                                sourceDoc.selection = null;
                                
                                var updatedItems = app.activeDocument.placedItems.length;
                                var artItem = app.activeDocument.placedItems[0];
                            
                                //have to make this to retrieve ALL linked items, even those linked inside others links (recursive)
                                while ( (updatedItems>0) && ( artItem.name > "") ) {
                                    updatedItems=app.activeDocument.placedItems.length;
                                    
                                    //loop through all linked items of the doc
                                    for ( i = 0; i < updatedItems; i++ ) {
                                        
                                        artItem = app.activeDocument.placedItems[i];
                                        alert("artItem.name "+ artItem.name);
                                        
                                        if ( artItem.name > "") 
                                        {
                                        // get the file reference path
                                        myAsset = File(artItem.file.fsName);  
                                        alert("myAsset "+ myAsset);
                                        
                                        //save info from this item
                                        pos = [artItem.left,artItem.top];  
                                        width = artItem.width;
                                        height = artItem.height;
                                        
                                        // CC 2015 only, open item as edit in new doc
                                        app.openCloudLibraryAssetForEditing(myAsset,myAsset);  
                                        // selectall, then group then copy
                                        app.executeMenuCommand ('selectall');
                                        app.executeMenuCommand ('group');               
                                        app.executeMenuCommand ('copy');    
                                        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);  
                                        
                                        // return to doc
                                        sourceDoc.activate();
                                        //paste the group from the edited library item
                                        app.executeMenuCommand ('paste');
                                        //position it over the original linked item, with original size
                                        sourceDoc.selection[0].position = pos;
                                        sourceDoc.selection[0].width = width;
                                        sourceDoc.selection[0].height = height;
                                        
                                        //remove the linked item
                                        artItem.remove();  
                                        }
                                        else{
                                            //next item
                                            i= i + 1;                
                                            alert("i "+ i);
                                        }
                                    }  
                                }
                            }