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

ScriptUI styles dropdown list : how to access to style groups?

Explorer ,
Jun 10, 2014 Jun 10, 2014

Hello,

I'm trying to build an UI to select Table, Cell and Paragraph styles for further table processing (see my script below)

So I used dropdown list menus for displaying styles. But I only got first level styles and not style groups and their contents.

My question is : is it possible and how to get dropdown sub-menus to acces to styles groups and their contents?

TIA

Nicolas

My javascript :

//UI to select Table, Cell and Paragraph styles for further tables processing in a document

myStyleChoices = myInput ();

myTableStyle = myStyleChoices[0] ;

myCellSTyle = myStyleChoices[1] ;

myParStyle = myStyleChoices[2] ;

function myInput ()

{

var myParStylesList = app.activeDocument.paragraphStyles.everyItem().name

var myCellStylesList = app.activeDocument.cellStyles.everyItem().name

var myTableStylesList = app.activeDocument.tableStyles.everyItem().name

var w = new Window ("dialog", "Apply to table :");

var myInputGroup3 = w.add ("group");

myInputGroup3.alignment = "left";

myInputGroup3.add ("statictext", undefined, "Table style :");

var myDropdown3 =myInputGroup3.add ("dropdownlist", undefined, myTableStylesList);

myDropdown3.selection = 1 ;

var myInputGroup2 = w.add ("group");

myInputGroup2.alignment = "left";

myInputGroup2.add ("statictext", undefined, "Cell style :");

var myDropdown2 =myInputGroup2.add ("dropdownlist", undefined, myCellStylesList);

myDropdown2.selection = 1 ;

var myInputGroup1 = w.add ("group");

myInputGroup1.add ("statictext", undefined, "Paragraph style :");

myInputGroup1.alignment = "left";

var myDropdown1 = myInputGroup1.add ("dropdownlist", undefined, myParStylesList);

myDropdown1.selection = 1 ;

var myButtonGroup = w.add ("group");

myButtonGroup.alignment = "right";

myButtonGroup.add ("button", undefined, "OK");

myButtonGroup.add ("button", undefined, "Cancel");

w.show ();

r = [myDropdown3.selection.text , myDropdown2.selection.text , myDropdown1.selection.text] ;

return r ;

}

TOPICS
Scripting
1.7K
Translate
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
Explorer ,
Mar 30, 2016 Mar 30, 2016

Nicolas,

You have probably figures this out already, but since it is nice to find answers here.

doc = app.activeDocument;

// Access to individual style.

firstGroupFirstItem = doc.paragraphStyleGroups.item(0).paragraphStyles[0].name;

// Array of stylenames from the first group.

styleNameArr = doc.paragraphStyleGroups.item(0).paragraphStyles.everyItem().name;

Cheers!

O.

Translate
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
People's Champ ,
Mar 30, 2016 Mar 30, 2016

Consider myDoc.allParagraphStyles, allCharacterStyles, allObjectStyles…

Loic

Ozalto | Productivity Oriented - Loïc Aigon

Translate
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
Explorer ,
Mar 30, 2016 Mar 30, 2016

Yes, they are very convenient. How about presenting the groups in a ddl with allParagraphStyles?

Translate
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
Enthusiast ,
Mar 30, 2016 Mar 30, 2016

Hi,

Like this ...

var _AllParaStyles = app.activeDocument.allParagraphStyles;

var myParStylesList = new Array()

for(var i=0;i<_AllParaStyles.length;i++){

    if (_AllParaStyles.parent instanceof ParagraphStyleGroup ){

        myParStylesList.push(_AllParaStyles.name.concat(' [',_AllParaStyles.parent.name),']')

    }else{

         myParStylesList.push(_AllParaStyles.name)

     }

}

Translate
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
People's Champ ,
Mar 30, 2016 Mar 30, 2016

Another approach:

Array.prototype.getExtendedName = function() {

  var n = this.length, i = 0, parent;

  var newArray = [];

  while ( i<n ) {

  parent = ( this.parent instanceof Document )? "" : this.parent.name+"//";

  newArray[ newArray.length ] = parent+this.name;

  i++;

  }

  return newArray;

}

app.activeDocument.allParagraphStyles.getExtendedName();

Loic

Ozalto | Productivity Oriented - Loïc Aigon

Translate
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 ,
Mar 30, 2016 Mar 30, 2016
LATEST
Translate
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