Skip to main content
April 19, 2019
Répondu

Stroke script removes stroke color from everything on spread?

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  

};

Ce sujet a été fermé aux réponses.
Meilleure réponse par 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 commentaire

willcampbell7
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.