Copy link to clipboard
Copied
Hi There,
Please can someone help with a question about setting the Paragraph Shading colour within a Paragraph Style.
I've tried a few things but as yet haven't managed to nail it.
Here's the snippet I've been testing...
allPars = app.activeDocument.allParagraphStyles;
for (var g = 1; g < allPars.length; g++) {
allPars[g].paragraphShadingColor.name = "This Colour";
allPars[g].paragraphShadingColor.name = allPars.itemByName("This Colour");
} Neither of the two versions, shown above, work?
Is this not possible via a script?
Thanks.
Hi @Nick37129562ryen , You don’t need .name—this assumes a Swatch named "This Color" exists"
var d = app.activeDocument
var allPars = d.allParagraphStyles;
for (var g = 1; g < allPars.length; g++) {
allPars[g].paragraphShadingColor = "This Color";
}
If you are not sure "This Color" exists then:
var d = app.activeDocument
var allPars = d.allParagraphStyles;
var sc = makeSwatch(d, "This Color")
//set the color’s properties
sc.properties = {space:ColorSpace.CMYK, colorValue:[0,50,0,0]}
Try this:
var doc = app.activeDocument;
var allPars = doc.allParagraphStyles;
var sw = doc.swatches.itemByName("This Colour");
for (var g = 1; g < allPars.length; g++) {
var s = allPars[g];
s.paragraphShadingOn = true;
s.paragraphShadingColor = sw;
//s.paragraphShadingTint = 100; // optional
}
Copy link to clipboard
Copied
Hi @Nick37129562ryen , You don’t need .name—this assumes a Swatch named "This Color" exists"
var d = app.activeDocument
var allPars = d.allParagraphStyles;
for (var g = 1; g < allPars.length; g++) {
allPars[g].paragraphShadingColor = "This Color";
}
If you are not sure "This Color" exists then:
var d = app.activeDocument
var allPars = d.allParagraphStyles;
var sc = makeSwatch(d, "This Color")
//set the color’s properties
sc.properties = {space:ColorSpace.CMYK, colorValue:[0,50,0,0]}
for (var g = 1; g < allPars.length; g++) {
allPars[g].paragraphShadingColor = "This Color";
}
/**
* Makes a new named Swatch
* @ param the document to add the color to
* @ param color name
* @ return the new swatch
*/
function makeSwatch(d, n){
if (d.colors.itemByName(n).isValid) {
return d.colors.itemByName(n);
} else {
return d.colors.add({name:n});
}
}Copy link to clipboard
Copied
Great! Thanks for the help Rob, much appreciated 🙂
Copy link to clipboard
Copied
Try this:
var doc = app.activeDocument;
var allPars = doc.allParagraphStyles;
var sw = doc.swatches.itemByName("This Colour");
for (var g = 1; g < allPars.length; g++) {
var s = allPars[g];
s.paragraphShadingOn = true;
s.paragraphShadingColor = sw;
//s.paragraphShadingTint = 100; // optional
}
Copy link to clipboard
Copied
Great! Thanks for the help Prabu, much appreciated 🙂
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more