Skip to main content
January 3, 2012
Answered

Select path using script

  • January 3, 2012
  • 1 reply
  • 6757 views

Hi,

Every now and than I have lots of images to save for the web (1-2k images in one time). All the images are .psd and have or path or transparent background. I would like to select the path and erease backgrount to make triming possible. The paths are named different so it is another problem because actions in photoshop select only specific name of the path. So is it possible to select path regardless of its name? Or how to write script for selecting several names of paths (ie "path 1", "path 2", "selection 1"...) I hope you understand what i want to do...

I have another script which resizing images to corect size and save it for web. So when I have jpg's with white backgroound first I run action in photoshop to trim all images and then I run script to resize all images because script check if image is wider or higher...

If you need more information just ask... I have CS5 version Photoshop

regards,

voahyeah

Edit:

For now I wrote this :

app.activeDocument.pathItems.getByName('Path 2').makeSelection();

app.activeDocument.selection.invert();

app.activeDocument.selection.clear();

and it select only if the name of the path is 'Path 2' else it stops...

So when the namme is Path 2 everything is fine but I have 10-15 different names.... so it would be great to avoid name of the path. If it is possible to select the first parh (if there is more than one)

or if it is not possible to avoid path name how to wrote if els if block for this to check all path names...?

... thanks

This topic has been closed for replies.
Correct answer

Hi Voahyeah,

Here is the Code........

if (app.documents.length > 0) {

    var docRef = app.activeDocument;

    var n = docRef.pathItems.length;

        if((n>0)&&(docRef.pathItems[0].name!="Work path" ))  {

             docRef.pathItems[0].makeSelection();

             docRef.selection.invert();

             docRef.selection.clear();

             docRef.trim(TrimType.TOPLEFT);

             docRef.selection.deselect();

           }

};

Regards,

- yajiv

1 reply

January 3, 2012

Hi Voahyeah,

Can you tell me Step by step procedure you followed.

I will help you.

Regards,

-yajiv

January 3, 2012

Hi yajiv_viki

I tried something like this

if (app.activeDocument.pathItems.getByName('Path 1'))

{

app.activeDocument.pathItems.getByName('Path 1').makeSelection();

app.activeDocument.selection.invert();

app.activeDocument.selection.clear();

}

else if (app.activeDocument.pathItems.getByName('Path 2'))

{

app.activeDocument.pathItems.getByName('Path 2').makeSelection();

app.activeDocument.selection.invert();

app.activeDocument.selection.clear();

}

But it isnt working. If you want I can post whole script... but it is important to me to make selection of path (regardles of its name) invert selection and clear to make triming possible..

regards

Correct answer
January 3, 2012

Hi Voahyeah,

Here is the Code........

if (app.documents.length > 0) {

    var docRef = app.activeDocument;

    var n = docRef.pathItems.length;

        if((n>0)&&(docRef.pathItems[0].name!="Work path" ))  {

             docRef.pathItems[0].makeSelection();

             docRef.selection.invert();

             docRef.selection.clear();

             docRef.trim(TrimType.TOPLEFT);

             docRef.selection.deselect();

           }

};

Regards,

- yajiv