简体   繁体   中英

Based On Styling Indesign Javascript Scripting CC

I would like to know how I can set (either directly or some other alternative method) the style property of "Based on" using JavaScript within Adobe InDesign CC. If I could also ask for documentation leading to an answer for reference it would be immensely appreciated.

My code:

var myPStyles = app.activeDocument.paragraphStyles;
var myPGroupStyles = app.activeDocument.paragraphStyleGroups;

// paragraph style 0 [No Paragraph Style]
// paragraph style 1 [Basic Paragraph Style]

var masterPGroupStyles = myPGroupStyles.add({name:"Master Fonts"});
var masterFont1 = masterPGroupStyles.paragraphStyles.add({name:"Font1"});
var masterFont2 = masterPGroupStyles.paragraphStyles.add({name:"Font2"});

Goal: To base Font2 on Font1

That property is called (not quite surprisingly) basedOn . The following will work to create your masterFont2 style based on masterFont1 :

var masterFont2 = masterPGroupStyles.paragraphStyles.add({name:"Font2", basedOn:masterFont1});

Contrary to what you say in your post, not providing a basedOn property will not assign "Basic Paragraph Style", it will always be "No Paragraph Style".


You can find all properties of paragraph styles in the ExtendScript Toolkit Editor that comes with InDesign, in the Object Model Viewer under "Help". Enter 'paragraphStyle' (singular) in the Search field and you will get a list of topics. Then open the panel "Browser" and you'll see ... oh wait, I haven't used the ESTK for so long I actually forgot why I hated it: you will get this not so useful flash card:

伊皮卡耶

All the help is available and I have been told you can actually reach it with this fancy interface, but these days I simply don't bother. Depending on your version of InDesign (actually the differences are only minor), check my cached version at MIT of Class ParagraphStyle for CS6 (older versions are available there as well) or, for CC-and-newer, Gregor Fellenz' InDesign ExtendScript API (10.0) - ParagraphStyle .

Both of these sets of pages are generated from the exact same data that Adobe uses for its own editor, but the data appears in a much friendlier format. The MIT version lacks a search box, but the files can be downloaded from my own site in CHM compiled form. Gregor's site comes complete with nice search fields.

These both are reference sites and assume basic knowledge of Javascript and its interface to InDesign's Document Object Model. For more information on the basics, you can always check Adobe's own list of introductions and tutorials .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM