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:
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();
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
...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();
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!
Copy link to clipboard
Copied
Glad to help. Good luck. 😃