Monday, October 26, 2020

#1 2020-10-11 09:30:37 am

Paul Smith
Member
Registered: 2020-10-09
Posts: 5

Applying next paragraph style in InDesign

Hi,

I have written a script that pulls text into a text box and successfully applies a paragraph style that is also defined in the script.

In the code that defines the paragraph style I also denote a 'next style'. This all works properly and when I go to InDesign after running the script the text has the correct style applied to it and the style has the correct 'next' style and I can maually, in InDesign, select 'Apply <Paragraph Style> then Next style'

My problem is that I cannot  'Apply <Paragraph Style> then Next style' from within the Applescript. It's frustrating. Everything is there and everything works and I can do the apply manually in InDesign but how do I  'Apply <Paragraph Style> then Next style' in Applescript.

Here is the part of the code that pulls the text in and applies my paragraph style. It all works fine but I need it to Apply then next.

Many thanks for any help.

Applescript:

tell myDocument
       set myTextFrame to make text frame of page 1 of myDocument with properties {stroke color:"None", fill color:"None"}
       --Set the bounds of the text frame.
       set geometric bounds of myTextFrame to {0, 0, 170, 160}
       --Enter text in the text frame.
       set contents of myTextFrame to ndstring1
       set applied paragraph style of text of myTextFrame to "Notable Date"
       set geometric bounds of myTextFrame to {54.25, 6, 144.307, 60}
end tell

Offline

 

#2 2020-10-11 06:51:25 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 971

Re: Applying next paragraph style in InDesign

Hi. I'm not sure if you're actually expecting nested style behavior, which may affect immediate visual changes. If a paragraph style is defined with another style as its next, you need to add something after the target to assume the second style's properties.

Offline

 

#3 2020-10-12 04:02:35 am

Paul Smith
Member
Registered: 2020-10-09
Posts: 5

Re: Applying next paragraph style in InDesign

Hi Marc. Thank you for your reply.
Everything works exactly as I want it to except applying the 'next' style. It's the 'something after the target' that I'm hoping someone can help me with. I'm just not finding the right syntax for it to apply the style and the next style. It always just applies the style without apllying the 'next' style too.

Offline

 

#4 2020-10-12 01:18:37 pm

kerflooey
Member
Registered: 2011-07-07
Posts: 190

Re: Applying next paragraph style in InDesign

--Hi. If you mean that if you have 2 paragraph styles defined, eg, "testparastyle" and "testparastyle_next", and you want the definition of "testparastyle" to specify "testparastyle_next" to be the Next Style in the definition of the "testparastyle" paragraph style, then you should be able to use something like:

Applescript:


tell application id "com.adobe.indesign"
   tell document 1        
       set next style of paragraph style "testparastyle" to paragraph style "testparastyle_next"
   end tell
end tell

-- InD 2020; Mojave

Last edited by kerflooey (2020-10-12 01:19:52 pm)

Offline

 

#5 2020-10-12 07:39:09 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 971

Re: Applying next paragraph style in InDesign

Hmm, it appears that I was mistaken, as the AppleScript functionality for next style diverges from the real-world application in a rather non-intuitive and cumbersome way; you'll need to edit an object style. It would likely be preferable to avoid the below method and simply assign the next paragraph style explicitly.

Applescript:

tell application "adobe indesign cs3"'s document 1
   set object style "[Basic Text Frame]"'s properties to {applied paragraph style:"A", apply next paragraph style:1}
   set text frame 1's parent text frame's paragraph 1's applied paragraph style to "A"
end tell

Offline

 

#6 2020-10-15 01:38:45 am

Paul Smith
Member
Registered: 2020-10-09
Posts: 5

Re: Applying next paragraph style in InDesign

kerflooey wrote:

--Hi. If you mean that if you have 2 paragraph styles defined, eg, "testparastyle" and "testparastyle_next", and you want the definition of "testparastyle" to specify "testparastyle_next" to be the Next Style in the definition of the "testparastyle" paragraph style, then you should be able to use something like:



Many thanks for your reply kerflooey.

I have successfully defined all styles I need and have also defined what is the 'next' paragraph style.
When I go to InDesign everything is as it should be.

The issue I'm having is actually applying the paragraph style and next style through Applescript.
I can apply the paragraph style but the syntax for applying paragraph style and next style is what is eluding me.

Again, if I go to InDesign, select the text box and manually apply paragraph style and next style it all works exactly as it should. I just need to try and nail the syntax for doing that in the Applescript.

Offline

 

#7 2020-10-15 01:42:36 am

Paul Smith
Member
Registered: 2020-10-09
Posts: 5

Re: Applying next paragraph style in InDesign

Marc Anthony wrote:

Hmm, it appears that I was mistaken, as the AppleScript functionality for next style diverges from the real-world application in a rather non-intuitive and cumbersome way; you'll need to edit an object style. It would likely be preferable to avoid the below method and simply assign the next paragraph style explicitly.



Many thanks for your reply Marc. Yes, it's a slippery little rascal isn't it!!
I'm trying to make your methodology work but I like your sentence

' It would likely be preferable to avoid the below method and simply assign the next paragraph style explicitly.'

That's exactly what I'm trying to do but, alas, with no success yet.

Again, many thanks for your help. You have put me on a new tract.

Offline

 

#8 2020-10-15 06:31:51 am

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 971

Re: Applying next paragraph style in InDesign

For clarification, what I meant by saying you should assign the next style explicitly is that you apply all paragraph styles explicitly, as needed, rather than using the semi-automated next style feature that requires an object style to work.

set paragraph 1's applied paragraph style to "A"
set paragraph 2's applied paragraph style to "B"
set paragraph 3's applied paragraph style to "C"
--etc

Offline

 

#9 2020-10-15 08:42:08 am

Paul Smith
Member
Registered: 2020-10-09
Posts: 5

Re: Applying next paragraph style in InDesign

Okey Dokey, I solved it...

What I had (bearing in mind this is just a small part of a much larger script)...

Applescript:

tell myDocument
set myTextFrame to make text frame of page 1 of myDocument with properties {stroke color:"None", fill color:"None"}
--Set the temporary bounds of the text frame.
set geometric bounds of myTextFrame to {0, 0, 170, 160}
--Enter text in the text frame.
set contents of myTextFrame to ndstring1
set applied paragraph style of text of myTextFrame to "Notable Date"
set geometric bounds of myTextFrame to {54.25, 6, 144.307, 60}
end tell

The paragraph style "Notable Date" is correctly defined (with its 'next' style) earlier in the script.

To make it apply the paragraph style and next style I did this:

Applescript:

tell myDocument
       set myTextFrame to make text frame of page 1 of myDocument with properties {stroke color:"None", fill color:"None"}
       --Set the temporary bounds of the text frame.
       set geometric bounds of myTextFrame to {0, 0, 170, 160}
       --Enter text in the text frame.
       set contents of myTextFrame to ndstring1
       
       set applied paragraph style of text of myTextFrame to "Notable Date"
       
       tell selection
           set applied paragraph style of text of myTextFrame to next style of myParagraphWeekday
       end tell
               
       set geometric bounds of myTextFrame to {54.25, 6, 144.307, 60}
end tell

It wouldn't accept "Notable Date" in this line:

Applescript:

set applied paragraph style of text of myTextFrame to next style of myParagraphWeekday

So I had to use the variable name I used when defining the style, which is myParagraphWeekday.

So it finally works. Many thanks for all help given. It made me think along other lines.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)