Article View: adobe.scripting.indesign
Article #8753Re: Script that can convert character attribs to character stylesheets
From: Peter_Kahrel
Date: Thu, 28 Sep 2006 14:14
Date: Thu, 28 Sep 2006 14:14
34 lines
2228 bytes
2228 bytes
For the variety I'll kick in with yet another possibility which I've been using for a while. It does the same as Martin's and Dave's script, but the approach is different. It creates character styles on the fly with attributes set (if the style doesn't already exist).
Peter
// attr2style takes two arguments: (1) a string to set the search
// and the attribute value in the style, and (2) a name for the character style.
attr2style( 'fontStyle = "Bold Italic"' , 'bolditalic' );
attr2style( 'fontStyle = "Bold"' , 'bold' );
attr2style( 'fontStyle = "Italic"' , 'italic' );
attr2style( 'position = Position.superscript' , 'super' );
attr2style( 'position = Position.subscript' , 'sub' );
attr2style( 'capitalization = Capitalization.smallCaps' , 'sc' );
attr2style( 'underline = true' , 'ul' );
attr2style( 'strikeThru = true' , 'strike' );
function attr2style( attr, st )
{
app.findPreferences = app.changePreferences = null;
eval( 'app.findPreferences.' + attr );
app.changePreferences.appliedCharacterStyle = checkStyle( attr, st );
app.activeDocument.search( '', false, false, '' );
}
function checkStyle( attr, stylename )
{
if( app.activeDocument.characterStyles.item( stylename ) == null )
{
app.activeDocument.characterStyles.add( { name : stylename } );
eval( 'app.activeDocument.characterStyles.item( stylename ).' + attr );
}
return app.activeDocument.characterStyles.item( stylename );
}
Technical Details
Message-ID:
<3bc1cee8.5@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeed.freenet.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: Peter_Kahrel@adobeforums.com Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeed.freenet.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.5@webcrossing.la2eafNXanI> Date: Thu, 28 Sep 2006 07:14:03 -0700 References: <3bc1cee8.-1@webcrossing.la2eafNXanI> Lines: 39 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit