• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is there a way to select pathItems base on stroke size and spotcolor?

Explorer ,
Jul 21, 2017 Jul 21, 2017

Copy link to clipboard

Copied

Hi Everyone,

I am a entry level scriptor and I am currently stuck on this one specific step. I am trying to have a script loop through pathItems and select a path that matches these criterias:

  • Stroke is using spotcolor name "BLACK" with No Fill
  • Stroke is size at 2pt

I have found a script that loops through pathItems and selects paths with a specific point size, but I am having trouble add the part where it selects a path with the assign color "BLACK" on the stroke. Can anyone help me with this script?

// script.name = selectPathsThisSize.jsx; 

// script.description = selects pathItems that have the same supplied stroke width; limited to 3 decimals; 

// script.required = a document with at least one path item; 

// script.parent = CarlosCanto // 6/5/11; 

// script.elegant = false; 

 

var idoc = app.activeDocument; 

var strokewidth = 2

//prompt ("Enter Stroke Width in points of paths to be selected", 0.361, "Select Paths this size:___"); 

 

for (i=0 ; i< idoc.pathItems.length; i++) {

   

          var ipath = idoc.pathItems

               if ((ipath.strokeWidth).toFixed(3) == Number(strokewidth).toFixed(3)) {

                  

                       

                         ipath.selected = true; 

                    } 

     } 

 

app.redraw(); 

TOPICS
Scripting

Views

791

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 21, 2017 Jul 21, 2017

The property you're looking for is strokeColor.spot.name. like this:

if(ipath.strokeColor.spot.name == "BLACK")

{

     //do something

}

and to check whether there's no fill, you need to check the filled property, like so

if(!ipath.filled)

{

     //do something

}

then just combine both of those in the same conditional:

if(!ipath.filled && ipath.strokeColor.spot.name === "BLACK")

{

     //do something

}

here's a quick snippet that's tested and working. I'm not sure why your snippet was using the toFixed() method

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 21, 2017 Jul 21, 2017

Copy link to clipboard

Copied

The property you're looking for is strokeColor.spot.name. like this:

if(ipath.strokeColor.spot.name == "BLACK")

{

     //do something

}

and to check whether there's no fill, you need to check the filled property, like so

if(!ipath.filled)

{

     //do something

}

then just combine both of those in the same conditional:

if(!ipath.filled && ipath.strokeColor.spot.name === "BLACK")

{

     //do something

}

here's a quick snippet that's tested and working. I'm not sure why your snippet was using the toFixed() method. Since you were declaring a desired stroke width of 2pt, there should be no need to convert that to 2.00. if the strokeWidth of ipath is 2.25, then it's not equal to 2 or 2.00. Save yourself some calculations and leave out those extra methods.

function test()

{

    var docRef = app.activeDocument;

    var paths = docRef.pathItems;

    var len = paths.length;

    var strokeWidth = 2;

    for(var x=0; x < len; x++)

    {

        var iPath = paths;

        if(iPath.strokeWidth == strokeWidth && iPath.strokeColor.spot.name == "BLACK" && !iPath.filled)

        {

            iPath.selected = true;

        }

    }

}

test();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 21, 2017 Jul 21, 2017

Copy link to clipboard

Copied

Oh wow, this is definately what I needed. Your script is very easy to understand. Thank you so much for explaining how which parts I need and how to put it together into a function. This is very helpful!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2017 Jul 21, 2017

Copy link to clipboard

Copied

LATEST

Glad to help. Good luck. 😃

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines