• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Changing nested styles

Community Beginner ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

Hi there,

Can anyone explain how to change nested styles with script?

I have a simple script that can change some parameters in the paragraph style, but I cant find out how to change the nested parameters.

I'm not a scripter and Google is my friend, but this question I can't find the answer for.

I use to bachprocess a lot of templates so it would be awesome if someone can tell me what to do.

Here's my simple script:

#target "InDesign-8.0"

if (app.documents.length != 0){   

var myD = app.activeDocument;

try {

var my_pstyle  = myD.paragraphStyles.item("6 BILD platta");

with (my_pstyle){

appliedFont = "Guardian AgateSans2";

fontStyle = "Regular";

rightIndent = 3;

}

}

catch (myError) {}

}

Here's what I want to change in the pstyle:

TOPICS
Scripting

Views

637

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 12, 2017 Jan 12, 2017

Do you want to change the nested items in an existing style, or do you want to add the nesting parameters as shown in the image to your new style?

Anyway, you can look at ParagraphStyle.nestedStyle and the NestedStyle Object itself. You can most likely just use .add "as usual", i.e.,

with (my_pstyle)

{

  nestedStyles.add({.appliedCharacterStyle:app.activeDocument.characterStyles.item("6 BILD platta fotograf"), delimiter:"^y", repetition:1, inclusive:true});
}

You can fiddle with its parameters until y

...

Votes

Translate

Translate
Community Expert ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

Do you want to change the nested items in an existing style, or do you want to add the nesting parameters as shown in the image to your new style?

Anyway, you can look at ParagraphStyle.nestedStyle and the NestedStyle Object itself. You can most likely just use .add "as usual", i.e.,

with (my_pstyle)

{

  nestedStyles.add({.appliedCharacterStyle:app.activeDocument.characterStyles.item("6 BILD platta fotograf"), delimiter:"^y", repetition:1, inclusive:true});
}

You can fiddle with its parameters until you get the right settings, or inspect them in an existing style.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

Thank's man. I will try that.

I want to change the nested items in an existing style.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

That should be possible: check each of the nested style's until you find the one to change, and then you can change the property you want to alter. Just set that property to the new value.

Here is a quickie to list the important properties (written on a CS4 machine but hey, not much changed so far):

st = app.activeDocument.paragraphStyles.item("6 BILD platta");

r = [];

for (ns=0; ns<st.nestedStyles.length; ns++)

{

r.push ("nested style #"+ns+":");

for (i in st.nestedStyles[0])

  if (i != 'parent' && i != 'properties' && i != 'index' && i != 'isValid')

  if (i == 'appliedCharacterStyle')

    r.push (i+'='+st.nestedStyles[0].name);

  else

    r.push (i+'='+st.nestedStyles[0]);

}

alert (r.join('\r'));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

Hi [Jongware],

If I just want to modify an existing nested style inserted in a "xxx" specific para style, is that code correct?

Thanks in advance! 

app.activeDocument.paragraphStyles.item("xxx").nestedStyles[0].properties = {appliedCharacterStyle:app.activeDocument.characterStyles.item("yyy"), inclusive: false, repetition: 5, delimiter: "^y"};

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

My code is working Obi-Wan-Kenobi​

This part Jongware wrote:

with (my_pstyle){

{

  nestedStyles.add({appliedCharacterStyle:app.activeDocument.characterStyles.item("6 BILD platta fotograf"), delimiter:"^y", repetition:2, inclusive:true});

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

LATEST

Sure – or at least, I think so. But you need to know in advance what index the nested style has (if the style has more than one). Yeah I know, "surely you can count them, from top to bottom", but I've been bitten by that before.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

I found a period in the code .appliedCharacterStyle:

with (my_pstyle)

{

  nestedStyles.add({.appliedCharacterStyle:app.activeDocument.characterStyles.item("6 BILD platta fotograf"), delimiter:"^y", repetition:1, inclusive:true});
}

If I remove that the code works great. Many thanks!

#target "InDesign-8.0"

if (app.documents.length != 0){  

var myD = app.activeDocument;

try {

var my_pstyle  = myD.paragraphStyles.item("6 BILD platta");

with (my_pstyle){

{

  nestedStyles.add({appliedCharacterStyle:app.activeDocument.characterStyles.item("6 BILD platta fotograf"), delimiter:"^y", repetition:2, inclusive:true});

}

}

}

catch (myError) {}

}

Maybe it's not the right way, but it works.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

Oops... (I didn't want to mess up the document I was working on so I did not test that part.)

Your correction looks okay!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines