Copy link to clipboard
Copied
Trying to delete everything that has a certain stroke color and *either* has a width or hieght of less than 7.
var docRef = app.activeDocument;
var selectedObjects = docRef.selection;
var CC = app.activeDocument.swatches.getByName ("CutContour").color;
for(i = docRef.pathItems.length-1; i >= 0; i--){
if(docRef.pathItems.strokeColor = CC && docRef.pathItems.width < 7 || docRef.pathItems.height < 7)
{
docRef.pathItems.remove();
}
}
I can get it to work for just the stoke color, and the width or height, but not all 3 together.
Thanks in advance, lots of helpful people on here and I really appreciate it.
Hi Silly-V,
not bad. But unfortunately this cannot work. (ONLY if all stroked objects are stroked with spot colors)
Otherwise the script fails.
That's why: replace your line 7 - 10
- if(thisItem.stroked == true && thisItem.strokeColor.spot.name == "CutContour"){
- if(thisItem.width > maxWidth || thisItem.height > maxHeight){
- thisItem.remove();
- }
with this:
...if(thisItem.stroked == true && thisItem.strokeColor.typename == "SpotColor" && thisItem.strokeColor.
Copy link to clipboard
Copied
Hi djbgraphicdesign,
there are several ways to do this. (I hope, I understand you right.)
One way could be:
if(docRef.pathItems.strokeColor = CC && docRef.pathItems.width < 7 || docRef.pathItems.strokeColor = CC && docRef.pathItems.height < 7) {
another way with nested if clauses:
if(docRef.pathItems.strokeColor = CC ) {
if(docRef.pathItems.width < 7 || docRef.pathItems.height < 7) {
(Do not forget the closing parentheses.)
Have fun
Copy link to clipboard
Copied
Shouldn't all those be double equals? ==
And I believe you can group them:
Copy link to clipboard
Copied
Yes, of course. This should be double equals.
(I copied the line number 5 in djbgraphicdesigns post and changed only the ands and ors – embarrassing).
Unfortunately I can my posting now no longer change.
Copy link to clipboard
Copied
Well I thought it was working earlier, but it is not, so sorry if you got a notification for my reply and then it wasn't there. What I did not realize is that I am having trouble deleting the items with the stroke color. I was unable to do it before, I thought I was but I didn't realize it was deleting everything regardless of the stroke color. So for now I am ignoring the width and height until I figure out what I am doing wrong here. I added the extra equal sign and now it's not deleting anything.
var docRef = app.activeDocument;
var CC = docRef.swatches.getByName("CutContour").color;
for(i = docRef.pathItems.length-1; i >= 0; i--){
if(docRef.pathItems.strokeColor == CC)
{
docRef.pathItems.remove();
}
}
Not sure what I am doing wrong here. CutContour is the name of the swatch and it is in the swatches pallet. It is also a spot color so idk if that changes everything. Thanks a lot for your help guys I am still new to javascript and even tho it is not working yet I am learning a little bit about syntax and how it is used.
Copy link to clipboard
Copied
Sorry, AND and OR works very well, but your script cannot work.
Please check this:
var docRef = app.activeDocument;
var CC = app.activeDocument.swatches.getByName ("CutContour").color;
alert("CC: " + CC)
try {
alert("CC: " + CC.spot.spotKind);
var CC_R = Math.round(CC.spot.color.red);
var CC_G = Math.round(CC.spot.color.green);
var CC_B = Math.round(CC.spot.color.blue);
alert("RGB_array [" + CC_R + ", " + CC_G + ", " + CC_B + "]");
}
catch (e) {
alert("CutContour isn't RGB Spotcolor swatch");
//var CC_M = Math.round(CC.spot.color.magenta);
// and so on
}
That's why IMHO it is better to work with:
var CC = app.activeDocument.swatches.getByName ("CutContour");
alert("CC: " + CC.name)
And:
Perhaps this helps you a little bit.
Copy link to clipboard
Copied
So his (or her) process should be more like:
var docRef = app.activeDocument;
var maxWidth = 7*72; //inches
var maxHeight = 7*72;
for(var i=docRef.pathItems.length-1; i>-1; i--){
var thisItem = docRef.pathItems;
if(thisItem.stroked == true && thisItem.strokeColor.spot.name == "CutContour"){
if(thisItem.width > maxWidth || thisItem.height > maxHeight){
thisItem.remove();
}
}
}
Copy link to clipboard
Copied
Hi Silly-V,
not bad. But unfortunately this cannot work. (ONLY if all stroked objects are stroked with spot colors)
Otherwise the script fails.
That's why: replace your line 7 - 10
- if(thisItem.stroked == true && thisItem.strokeColor.spot.name == "CutContour"){
- if(thisItem.width > maxWidth || thisItem.height > maxHeight){
- thisItem.remove();
- }
with this:
if(thisItem.stroked == true && thisItem.strokeColor.typename == "SpotColor" && thisItem.strokeColor.spot.name == "CutContour") {
if(thisItem.width < maxWidth || thisItem.height < maxHeight) {
thisItem.remove();
}
if there are no other hidden infos from you, then this should do the job. You only have to change the size of maxWidth and maxHeight with your own conversion factor (for your units).
Have fun
Copy link to clipboard
Copied
Touché! I did not think of that one.
Copy link to clipboard
Copied
Thanks guys, sorry it took a while for me to respond it's been a crazy week, but the script works great! Very happy about it, thanks again!