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:
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
...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.
Copy link to clipboard
Copied
Thank's man. I will try that.
I want to change the nested items in an existing style.
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'));
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"};
(^/)
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});
}
Copy link to clipboard
Copied
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.
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.
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!