Skip to main content
April 19, 2019
Answered

Stroke script removes stroke color from everything on spread?

  • April 19, 2019
  • 1 reply
  • 1102 views

The below is an awesome script that will place a stroke with a weight of .3 pt and color of grey (0 0 0  50) at 100% tint.

It works great, except, it removes grey from anything that uses it on the spread, if anything has grey to begin with.

I’m thinking I need a check function, or a conditional statement, i.e. “If, then”.

Something along the lines of:

“If there’s preexisting grey, then simply apply grey to the stroke, but if there is no preexisting grey, then add it to the swatches panel, then apply it.

Then it would be perfect, and usable.

Thanks.

var myDoc = app.activeDocument;

var sel = app.selection;  

var selLength = sel.length;  

try 

var myColor =  myDoc.colors.add({name : "C=0 M=0 Y=0 K=50", colorValue : [0,0,0,50] , model : ColorModel.PROCESS ,space : ColorSpace.CMYK });  

catch(e) 

myDoc.colors.item("C=0 M=0 Y=0 K=50").remove(); 

var myColor =  myDoc.colors.add({name : "C=0 M=0 Y=0 K=50", colorValue : [0,0,0,50] , model : ColorModel.PROCESS ,space : ColorSpace.CMYK }); 

for(var n=0;n<selLength;n++)  

var mySel = app.selection;  

mySel.strokeWeight = .3;  

mySel.strokeColor = myColor; 

mySel.strokeTint = 100;  

mySel.strokeAlignment = StrokeAlignment.INSIDE_ALIGNMENT  

};

This topic has been closed for replies.
Correct answer willcampbell7

Code looks odd -- adds a color then deletes it, only to add it again. I am guessing the call to delete the color is making anything already that color change to black.

Try this revision...

var myDoc = app.activeDocument;

var sel = app.selection;

var selLength = sel.length;

var myColor = myDoc.colors.item("C=0 M=0 Y=0 K=50");

try {

    myColor.name;

} catch (e) {

    // Doesn't exist; add it.

    myColor = myDoc.colors.add({name: "C=0 M=0 Y=0 K=50", colorValue: [0, 0, 0, 50], model: ColorModel.PROCESS, space: ColorSpace.CMYK});

}

for (var n = 0; n < selLength; n++) {

    var mySel = app.selection;

    mySel.strokeWeight = .3;

    mySel.strokeColor = myColor;

    mySel.strokeTint = 100;

    mySel.strokeAlignment = StrokeAlignment.INSIDE_ALIGNMENT;

}

1 reply

willcampbell7
willcampbell7Correct answer
Legend
April 19, 2019

Code looks odd -- adds a color then deletes it, only to add it again. I am guessing the call to delete the color is making anything already that color change to black.

Try this revision...

var myDoc = app.activeDocument;

var sel = app.selection;

var selLength = sel.length;

var myColor = myDoc.colors.item("C=0 M=0 Y=0 K=50");

try {

    myColor.name;

} catch (e) {

    // Doesn't exist; add it.

    myColor = myDoc.colors.add({name: "C=0 M=0 Y=0 K=50", colorValue: [0, 0, 0, 50], model: ColorModel.PROCESS, space: ColorSpace.CMYK});

}

for (var n = 0; n < selLength; n++) {

    var mySel = app.selection;

    mySel.strokeWeight = .3;

    mySel.strokeColor = myColor;

    mySel.strokeTint = 100;

    mySel.strokeAlignment = StrokeAlignment.INSIDE_ALIGNMENT;

}

William Campbell
April 19, 2019

Works like a charm.

Many thanks from the world of catalog production.

Cheers.