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

scripting with paragraph/character style folders

Community Beginner ,
Nov 02, 2020 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

465

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 ,
Nov 02, 2020 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

 

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 ,
Nov 02, 2020 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

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
Guide ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

Hi,

 

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

 

P.

 

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 ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

LATEST

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 )

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