Article View: adobe.scripting.indesign
Article #8730Re: Script that can convert character attribs to character stylesheets
From: Martin Fischer*
Date: Thu, 28 Sep 2006 08:13
Date: Thu, 28 Sep 2006 08:13
60 lines
3047 bytes
3047 bytes
Hi Martin,
you may try this one to catch Bold, Italic, Bold-Italic and SuperScript (SupScript is missing):
if (app.documents.length != 0){
var myCharacterStyleName;
var myCharacterStyleName ="Bold Italic";
myDefineCharacterStyle(myCharacterStyleName,"fontStyle");
var myCharacterStyleName ="Bold";
myDefineCharacterStyle(myCharacterStyleName,"fontStyle");
var myCharacterStyleName ="Italic";
myDefineCharacterStyle(myCharacterStyleName,"fontStyle");
var myCharacterStyleName ="SuperScript";
myDefineCharacterStyle(myCharacterStyleName,"SuperScript");
}
else{
alert("No documents are open. Please open a document, select some text, and try again.");
}
function myDefineCharacterStyle(myCharacterStyleName,myProp){
var myCharacterStyle;
var myDocument = app.documents[0];
noCharStyle = app.documents[0].characterStyles[0];
//Create the character style if it does not already exist.
myCharacterStyle = myDocument.characterStyles.item(myCharacterStyleName);
try{
myCharacterStyle.name;
}
catch (myError){
myCharacterStyle = myDocument.characterStyles.add({name:myCharacterStyleName});
}
app.findPreferences = null; app.changePreferences = null;
switch (myProp){
case "fontStyle":
myCharacterStyle.fontStyle = myCharacterStyleName;
myDocument.search("",false,false,undefined,{appliedCharacterStyle:noCharStyle,fontStyle:myCharacterStyleName},{appliedCharacterStyle:myCharacterStyle});
break;
case "SuperScript":
try{
mySwatch = myDocument.colors.add({name:"Red",space:ColorSpace.rgb,colorValue:Array(250,0,0)});
}
catch (myError){
mySwatch = myDocument.colors.item("Red");
}
myCharacterStyle.position = Position.superscript;
myCharacterStyle.fillColor = mySwatch;
myDocument.search("",false,false,undefined,{appliedCharacterStyle:noCharStyle,position:Position.superscript},{appliedCharacterStyle:myCharacterStyle});
break;
}
}
But I know that there is a script of Dave Saunders which will do this job too. And Dave's script catches Subscript by default too. ;-)
Martin
Technical Details
Message-ID:
<3bc1cee8.0@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!news2.volia.net!news.musoftware.de!news.albasani.net!news.isoc.lu!webcrossingReferences:
<3bc1cee8.-1@webcrossing.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,9f7c3ecb4b002363 X-Google-Attributes: gidf939a,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Martin Fischer*" <martin.fischer@online.de> Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!news2.volia.net!news.musoftware.de!news.albasani.net!news.isoc.lu!webcrossing Newsgroups: adobe.scripting.indesign Subject: Re: Script that can convert character attribs to character stylesheets Message-ID: <3bc1cee8.0@webcrossing.la2eafNXanI> Date: Thu, 28 Sep 2006 01:13:22 -0700 References: <3bc1cee8.-1@webcrossing.la2eafNXanI> Lines: 70 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit