Highlighted

scripting with paragraph/character style folders

Community Beginner ,
Nov 02, 2020

Copy link to clipboard

Copied

Hej!

I am trying to script around with paragraph/character styles.

Most of them are sorted in folders within the respective styles-window, but I keep getting errors when trying to work with the styles in a folder. I think I need to escape the slash or there's another syntax for styles-folders, but I cannot find anything about the issue...

The structure looks like this:

 

paragraph style 1a

paragraph style 2a

folder b/

   paragraph style 1b

   paragraph style 2b

folder c/

   paragraph style 1c

   paragraph style 2c

 

It works when everything is on the bottom level with no folders and I just call "paragraph style 1c", but not with "folder c/paragraph style 1c". And it would greatly improve usability to have folders...

Any thoughts? 🙂

 

Thank you & best wishes

Mathis

TOPICS
Scripting

Views

57

Likes

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

scripting with paragraph/character style folders

Community Beginner ,
Nov 02, 2020

Copy link to clipboard

Copied

Hej!

I am trying to script around with paragraph/character styles.

Most of them are sorted in folders within the respective styles-window, but I keep getting errors when trying to work with the styles in a folder. I think I need to escape the slash or there's another syntax for styles-folders, but I cannot find anything about the issue...

The structure looks like this:

 

paragraph style 1a

paragraph style 2a

folder b/

   paragraph style 1b

   paragraph style 2b

folder c/

   paragraph style 1c

   paragraph style 2c

 

It works when everything is on the bottom level with no folders and I just call "paragraph style 1c", but not with "folder c/paragraph style 1c". And it would greatly improve usability to have folders...

Any thoughts? 🙂

 

Thank you & best wishes

Mathis

TOPICS
Scripting

Views

58

Likes

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
Nov 02, 2020 0
Adobe Community Professional ,
Nov 02, 2020

Copy link to clipboard

Copied

What code causes the error. For referring to the style inside a paragraph style you will have to first iterate the style group and then iterate its style.

Document object has a paragraphStyleGroups and then this will have either more groups or style. To access paragraph style 1c under folder c, something like the following would work

 

var psg = app.activeDocument.paragraphStyleGroups.itemByName("folder c")
if(pag.isValid)
{
  var ps = psg.paragraphStyles.itemByName("paragraph style 1c")
  if(ps.isValid)
   alert("Found it)
}

 

-Manan

 

Likes

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
Reply
Loading...
Nov 02, 2020 0
Adobe Community Professional ,
Nov 02, 2020

Copy link to clipboard

Copied

Hi,

 

I don't think the "Folders" in the paragraph panel work like folders on you machine, I was unable to get a specific paragraph style using any kind of notation, I was able to get the paragraph style called "Paragraph Style 3" from all the groups by using .

 

 

var curDoc = app.activeDocument;
var paraStyle = curDoc.paragraphStyleGroups.everyItem().paragraphStyles.itemByName("Paragraph Style 3").getElements();

 

 

The only caveat is that this will return you all paragraph styles that match the name, it does not matter where they life, but if you know which group it is in then you can do this.

 

 

var curDoc = app.activeDocument;
var paraStyle = curDoc.paragraphStyleGroups.itemByName("Style Group 3").paragraphStyles.itemByName("Paragraph Style 3");

 

 

Hope this helps.

 

Regards

 

Malcolm

Likes

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
Reply
Loading...
Nov 02, 2020 1
Advisor ,
Nov 02, 2020

Copy link to clipboard

Copied

Hi,

 

Get allxxxxxStyles from the document and then look at the parent for a group.

 

P.

 

Likes

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
Reply
Loading...
Nov 02, 2020 1
Adobe Community Professional ,
Nov 02, 2020

Copy link to clipboard

Copied

Hi Mathis,

if you want to know the exact structure of your paragraph styles in your Paragraph Styles panel you could iterate through the allParagraphStyles array of your document. If you test for the value of parent of a given style in that array you will basically get two kinds of results:

 

[object Document] or [object ParagraphStyleGroup].

 

In case of [Object Document] the tested paragraph style is in the "root" of your Paragraph Styles panel.

In case of [object ParagraphStyleGroup] it is part of a paragraph style group. The tested style can be nested at any depth in the structure of nested paragraph style groups.

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
Nov 02, 2020 0