16 Replies Latest reply on Oct 3, 2015 2:09 PM by pixxxel schubser

    Get Clipping Path dimensions

    aiScripting Level 1

      Hello all!

      Ok so I've searched around a little and haven't found what I am looking for.

      I am looping through all the placedItems of the active document.

      Checking to see if it is selected and placing the name of the placed item above it.

      The issue I am running into is when its in a clipping mask then the location of the tag is way off (its where the placed would be if it wasn't clipped)

      So I need to get the location of the clipping mask of the placed item and use that to set the text there.

      Thanks

      -Boyd

        • 1. Re: Get Clipping Path dimensions
          Vinicius Baptista Level 2

          Hello

           

          Try, create one pathItem and clipped it, select it and use this command:

           

          alert(app.activeDocument.selection[0].pageItems[0].width);
          

           

          This will show an alert with the width of the clipped object, using the first object and ignoring what is hidden.

           

          Best regards

          Vinícius

          • 2. Re: Get Clipping Path dimensions
            Vinicius Baptista Level 2

            If it does not work or have any questions, post your script here, and I'll try to help you!

            • 3. Re: Get Clipping Path dimensions
              aiScripting Level 1

              Hello! Thanks for your quick reply!

              So that did give me the dimension I want. But I need it for each placed item... and some of the placed items won't be in a clipping mask (and when its not this code works fine)

              Here is what I have:

              var doc = app.activeDocument;
              var piobj = doc.placedItems;
              
              
              // loop through all the placed items
              for(i = 0; i<piobj.length; i++){
                  //Check to see if it is selected
                  if(piobj[i].selected == true){
                      //Here I pass the piobj to a function that gets its name, location and places the text above it.
                      addText(piobj[i]);
                  };
              };
              

               

              Thanks!

              -Boyd

              • 4. Re: Get Clipping Path dimensions
                Vinicius Baptista Level 2

                So sorry, I can't found the problem, Can I see this function for create the text, or the full code? I will test here with some placedItems.

                • 5. Re: Get Clipping Path dimensions
                  aiScripting Level 1

                  I guess where I am stumped is I am looping through the "placedItems" not page items.

                  Because I need to get the name of the placedItem and the dimensions and location of the placed item don't reflect the clipping mask.

                  If I loop through the "pageItems" I can find the pathItem that is clipping the image. But then I don't have the name of the placedItem only the location and size of where I want the text now.

                  • 6. Re: Get Clipping Path dimensions
                    aiScripting Level 1

                    Here is my code with the addText funciton:

                    var doc = app.activeDocument;
                    var piobj = doc.placedItems;
                    
                    
                    // loop through all the placed items
                    for(i = 0; i<piobj.length; i++){
                        //Check to see if it is selected
                        if(piobj[i].selected == true){
                            //Here I pass the piobj to a function that gets its name, location and places the text above it.
                            addText(piobj[i]);
                        };
                    };
                    
                    
                    function addText(pI){
                        var offsetUP = .7 * 72;
                        var aLayer = doc.activeLayer;
                      var tagText =  aLayer.textFrames.add();
                        tagText.contents = pI.file.name;
                        tagText.top = pI.top + offsetUP;
                        tagText.left = (pI.left + (pI.width /2)) - (tagText.width /2);
                    };
                    
                    • 7. Re: Get Clipping Path dimensions
                      Vinicius Baptista Level 2

                      Do not worry, that's normal when we're writing scripts, so I'm leaving work now and when I get home I will try to help you, maybe I have a similar script! See later!

                      • 8. Re: Get Clipping Path dimensions
                        Vinicius Baptista Level 2

                        Hey man try this:

                         

                        var doc = app.activeDocument;  
                        var piobj = doc.placedItems;  
                        var sel = app.activeDocument.selection[0].pageItems[0];
                          
                        // loop through all the placed items  
                        for(i = 0; i<piobj.length; i++){  
                            //Check to see if it is selected  
                            if(piobj[i].selected == true){  
                                //Here I pass the piobj to a function that gets its name, location and places the text above it.  
                                addText(piobj[i]);  
                            };  
                        };  
                          
                          
                        function addText(pI){  
                            var offsetUP = .7 * 72;  
                            var aLayer = doc.activeLayer;  
                          var tagText =  aLayer.textFrames.add();  
                            tagText.contents = pI.file.name;  
                            tagText.top = sel.top + offsetUP;  
                            tagText.left = (sel.left + (sel.width /2)) - (tagText.width /2);  
                        };  
                        

                         

                        That's working, you need only do a loop if the selection is multiple.

                         

                         

                        • 9. Re: Get Clipping Path dimensions
                          aiScripting Level 1

                          Thats getting closer to what I need!

                          But that only works if there is only one item. I need it to apply to many items. Some will be just placed pdfs some will be clipped placed items etc.

                          Thanks so much for your help! this will give me something to keep trying here

                          • 10. Re: Get Clipping Path dimensions
                            Vinicius Baptista Level 2

                            Finally, I think that's what you needed.

                             

                            var doc = app.activeDocument;    
                            var sel = app.activeDocument.selection;  
                            var selLength = sel.length;
                            var piobj = doc.placedItems;    
                            
                            
                            for(i=0; i<selLength; i++){
                                app.activeDocument.selection = sel[i];
                                for(j = 0; j<piobj.length; j++){    
                                    //Check to see if it is selected    
                                    if(piobj[j].selected == true){    
                                        //Here I pass the piobj to a function that gets its name, location and places the text above it.    
                                    var offsetUP = .7 * 72;     
                                    var aLayer = doc.activeLayer;     
                                    var tagText =  aLayer.textFrames.add();     
                                    tagText.contents = piobj[j].file.name;     
                                    tagText.top = app.activeDocument.selection[0].pageItems[0].top + offsetUP;     
                                    tagText.left = (app.activeDocument.selection[0].pageItems[0].left + (app.activeDocument.selection[0].pageItems[0].width /2)) - (tagText.width /2);     
                                    };    
                                };        
                            };
                            

                             

                            I hope helped you.

                             

                            Regards,

                            Vinícius

                            • 11. Re: Get Clipping Path dimensions
                              pixxxel schubser Level 5

                              aiScripting schrieb:

                               

                              Hello all!

                              Ok so I've searched around a little and haven't found what I am looking for.

                              I am looping through all the placedItems of the active document.

                              Checking to see if it is selected and placing the name of the placed item above it. …

                               

                              aiScripting,

                              ???

                              Why you go the „long way“?

                              Why you don't loop through your selection and check if the selected Items are placed items or not?

                               

                              e.g. like this:

                              var aDoc = app.activeDocument;
                              var theSel = aDoc.selection;
                              // for the first selected item
                              if (theSel[0].typename == "PlacedItem") {
                                  //insert here your personal code for this case
                                  alert(theSel[0].file.name);
                                  } 
                              

                               

                              Regards pixxxel schubser

                              Have fun

                               

                              • 12. Re: Get Clipping Path dimensions
                                Vinicius Baptista Level 2

                                Hey man, I found a mistake, the code only worked when the object was clipping mask, I fixed already putting a try catch to solve, enjoy:

                                 

                                var doc = app.activeDocument;    
                                var sel = app.activeDocument.selection;  
                                var selLength = sel.length;
                                var piobj = doc.placedItems;    
                                
                                
                                for(i=0; i<selLength; i++){
                                    app.activeDocument.selection = sel[i];
                                    for(j = 0; j<piobj.length; j++){    
                                        //Check to see if it is selected    
                                        if(piobj[j].selected == true){    
                                            //Here I pass the piobj to a function that gets its name, location and places the text above it.    
                                        var offsetUP = .7 * 72;     
                                        var aLayer = doc.activeLayer;     
                                        var tagText =  aLayer.textFrames.add();     
                                        tagText.contents = piobj[j].file.name;     
                                        try{
                                        tagText.top = app.activeDocument.selection[0].pageItems[0].top + offsetUP;     
                                        tagText.left = (app.activeDocument.selection[0].pageItems[0].left + (app.activeDocument.selection[0].pageItems[0].width /2)) - (tagText.width /2);     
                                        }catch(e){
                                        tagText.top = app.activeDocument.selection[0].top + offsetUP;     
                                        tagText.left = (app.activeDocument.selection[0].left + (app.activeDocument.selection[0].width /2)) - (tagText.width /2);     
                                        };
                                        };    
                                    };        
                                };
                                
                                • 13. Re: Get Clipping Path dimensions
                                  Vinicius Baptista Level 2

                                  Dear Pixxxel,

                                   

                                  Because sometimes this selection has clipped and he want return the dimensions of clipped object and not dimensions of placedItem.

                                   

                                  Best Regards,

                                  Vinícius

                                  • 14. Re: Get Clipping Path dimensions
                                    aiScripting Level 1

                                    Hello pixxxel schubser!

                                    So I originally did loop through the selection, But I ran into an issue where if the placed image was in a clipping mask and you just clicked on it (instead of dragging a selection over it) then it would only select the clipping mask making the placeditem not selected. And often more items are selected then there are placed items (because its easiest to just select all and run the script, and there are registration marks and other items in the document).

                                    So I am looping through the placed items because I need the name of the place item.

                                    sigh.... I seam to figure out how to get the location of the clipping mask or the name of the image, But not both

                                    • 15. Re: Get Clipping Path dimensions
                                      Vinicius Baptista Level 2

                                      Hello aiScripting, Are you tested my last script with "try catch"?? I did some testing and it worked perfectly. Really hope that works for you.

                                      • 16. Re: Get Clipping Path dimensions
                                        pixxxel schubser Level 5

                                        Again:

                                        You don't need to loop through your selection and through all of your placed items.

                                         

                                        I mean something like this:

                                        var aDoc = app.activeDocument;
                                        var theSel = aDoc.selection;
                                        // for the first selected item
                                        if (theSel[0].typename == "PlacedItem") {
                                            // --- // get the name and position
                                            //alert("without clipping mask");
                                            alert(theSel[0].file.name);
                                            //alert(theSel[0].position);
                                            } else {
                                                if (theSel[0].typename == "GroupItem" && theSel[0].clipped) {
                                                    if (theSel[0].pageItems[1].typename == "PlacedItem") {
                                                        // --- // get the name and position
                                                        //alert ("with clipping mask");
                                                        alert (theSel[0].pageItems[1].file.name);
                                                        // --- // but furthermore you need some maths to find the correct values of the clipped image
                                                        //alert ("clipping mask position: " + theSel[0].pageItems[0].position);
                                                        //alert ("placed item position: " + theSel[0].pageItems[1].position);
                                                        }
                                                    }
                                                }
                                        

                                         

                                        Have fun