Quantcast
Channel: Adobe Community: Message List - InDesign Scripting
Viewing all articles
Browse latest Browse all 37788

How to get fillColor for characterStyle

$
0
0

Hi

 

I'm trying to get the filColor for each paragraphStyle and characterStyle in a document. The (abbreviated) code below works just fine for paragraph styles.

 

        for (mySCounter = 0; mySCounter < myDoc.paragraphStyles.length; mySCounter ++) {            var myPS = myDoc.paragraphStyles.item(mySCounter);            if (myPS.name != "[No Paragraph Style]"& myPS.name != "[Basic Paragraph]"& myPS.name != "PAGER") {                myTF.insertionPoints.item(-1).contents = "p." + myPS.name + " {\r"                + "\tcolor: \"" + myPS.fillColor.name + "\";\r"                + "}\r";            }        }

 

When I adapt it for character styles, though, Extendscript Toolkit burps at me.

 

        for (mySCounter = 0; mySCounter < myDoc.characterStyles.length; mySCounter ++) {            var myCS = myDoc.characterStyles.item(mySCounter);            if (myCS.name != "[None]"& myCS.name != "pager") {                myTF.insertionPoints.item(-1).contents = "span." + myCS.name + " {\r"                + "\tcolor: \"" + myCS.fillColor.name + "\";\r"                + "}\r";           }        }

 

I've tried lots of variations with and without "name" in "myCSfillColor.name," including adding "toString()," "toSource()," and "toSpecifier()." The closest I can get to a valid return is "[object Color]." I'm not sure where the problem(s) lies, exactly. It could be that most of my character styles are returning a null, but that seems unlikely because I'm collecting other character style properties that are undefined, and they don't throw an error.

 

According to Jongware's help files, characterStyle.fillColor can return NothingEnum or a swatch while paragraphStyle.fillColor can only return a swatch. This seems to support the possiblity that those character styles that have no defined color are throwing the error, but I don't know what to do with that information. I could write an if statement, but the "\tcolor: ..." line above it in the middle of a long string that I'm building, and I can't think how I would put a conditional in the middle of that line.

 

Any thoughts on how I can capture the name of the fillColor for characterStyle? I can live with including "null" or "NOTHING" for those that are undefined.

 

I've pasted the full script below in case anyone wants to test it. It requires that a document be open and that it have at least one paragraph style other than "[Basic Paragraph]" and one character style other than "[None]." It will create a new document and dump into it selected properties of the paragraph and character styles (it's building a custom CSS template).

 

Thanks.

 

m.

 

CSS_Processor() // Invoke the framework for the processing routines      function CSS_Processor() {        app.textPreferences.typographersQuotes = false;        var myDoc = app.activeDocument;        var myStylesDoc = app.documents.add();        var myTF = myStylesDoc.pages.item(0).textFrames.add();        myTF.geometricBounds = [3, 3, 63, 48];        myTF.textFramePreferences.textColumnCount = 3;        for (mySCounter = 0; mySCounter < myDoc.paragraphStyles.length; mySCounter ++) {            var myPS = myDoc.paragraphStyles.item(mySCounter);            if (myPS.name != "[No Paragraph Style]"& myPS.name != "[Basic Paragraph]"& myPS.name != "PAGER") {                myTF.insertionPoints.item(-1).contents = "p." + myPS.name + " {\r"                + "\tfont-family: \"" + myPS.appliedFont.name.slice(0, myPS.appliedFont.name.indexOf("\t")) + "\";\r"                + "\tfont-style: \"" + myPS.fontStyle + "\";\r"                + "\tfont-size: \"" + myPS.pointSize + "\";\r"                + "\tline-height: \"" + myPS.leading + "\";\r"                + "\tletter-spacing: \"" + myPS.kerningMethod + "\";\r"                + "\tword-spacing: \"" + myPS.tracking + "\";\r"                + "\tvertical-align: \"" + myPS.baselineShift + "\";\r"                + "\ttext-align: \"" + myPS.justification.toString() + "\";\r"                + "\tmargin-left: \"" + myPS.leftIndent + "\";\r"                + "\tmargin-right: \"" + myPS.rightIndent + "\";\r"                + "\ttext-indent: \"" + myPS.firstLineIndent + "\";\r"                + "\tmargin-top: \"" + myPS.spaceBefore + "\";\r"                + "\tmargin-bottom: \"" + myPS.spaceAfter + "\";\r"                + "\torphans: \"" + myPS.keepFirstLines + "\";\r"                + "\twidows: \"" + myPS.keepLastLines + "\";\r"                + "\tkeep with next: \"" + myPS.keepWithNext + "\";\r"                + "\tcolor: \"" + myPS.fillColor.name + "\";\r"                + "\ttint: \"" + myPS.fillTint + "\";\r"                + "\tcase: \"" + myPS.capitalization.toString() + "\";\r"                + "\tposition: \"" + myPS.position.toString() + "\";\r"                + "\tunderline: \"" + myPS.underline + "\";\r"                + "\tstrikethrough: \"" + myPS.strikeThru + "\";\r"                + "\thyphenation: \"" + myPS.hyphenation + "\";\r"                + "}\r";            }        }          for (mySCounter = 0; mySCounter < myDoc.characterStyles.length; mySCounter ++) {            var myCS = myDoc.characterStyles.item(mySCounter);            if (myCS.name != "[None]"& myCS.name != "pager") {                myTF.insertionPoints.item(-1).contents = "span." + myCS.name + " {\r"                + "\tfont-family: \"" + myCS.appliedFont.toString() + "\";\r"                + "\tfont-style: \"" + myCS.fontStyle.toString() + "\";\r"                + "\tfont-size: \"" + myCS.pointSize.toString() + "\";\r"                + "\tline-height: \"" + myCS.leading.toString() + "\";\r"                + "\tletter-spacing: \"" + myCS.kerningMethod.toString() + "\";\r"                + "\tword-spacing: \"" + myCS.tracking.toString() + "\";\r"                + "\tvertical-align: \"" + myCS.baselineShift.toString() + "\";\r"                + "\tcolor: \"" + myCS.fillColor.toString() + "\";\r"                + "\ttint: \"" + myCS.fillTint.toString() + "\";\r"                + "\tcase: \"" + myCS.capitalization.toString() + "\";\r"                + "\tposition: \"" + myCS.position.toString() + "\";\r"                + "\tunderline: \"" + myCS.underline.toString() + "\";\r"                + "\tstrikethrough: \"" + myCS.strikeThru.toString() + "\";\r"                + "}\r";           }        }/*        myStylesDoc.exportFile(format:ExportFormat.TEXT_TYPE, to:folder.Desktop + "template.css");        myStylesDoc.close(); */        app.textPreferences.typographersQuotes = true;    }

Viewing all articles
Browse latest Browse all 37788

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>