Skip to main content
Inspiring
July 21, 2017
Answered

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

  • July 21, 2017
  • 2 replies
  • 1034 views

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(); 

This topic has been closed for replies.
Correct answer Disposition_Dev

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();

2 replies

lan.mineAuthor
Inspiring
July 21, 2017

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!

Disposition_Dev
Legend
July 21, 2017

Glad to help. Good luck. =)

Disposition_Dev
Disposition_DevCorrect answer
Legend
July 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. 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();