Copy link to clipboard
Copied
Hi Experts, I Have a Problem ,i think i reach my knowledge limit, so please help, i will show the problem in breif since my complete code is too long, simply i collect all the styles (Characters - paragraph - objects) and Show them in dropdown list in my Script UI, and the script is working correctly in showing the styles and style groups, i used the following :
//---------------------------------------------------------
//Adding Character Styles with Sub Groups
//---------------------------------------------------------
var mydoc = app.activeDocument;
myStyles = mydoc.allCharacterStyles;
var myCharsStyles = [];
for (i = 0; i < myStyles.length; i ++){
myCharsStyles[i] = myStyles[i].name;
if (myStyles[i].parent.constructor.name == "CharacterStyleGroup") myCharsStyles[i]+=" ["+myStyles[i].parent.name+"]";
}
//---------------------------------------------------------
//Adding Paragraph Styles with Sub Groups
//---------------------------------------------------------
var mydoc = app.activeDocument;
myStyles = mydoc.allParagraphStyles;
var myParStylesList = [];
for (i = 0; i < myStyles.length; i ++){
myParStylesList[i] = myStyles[i].name;
if (myStyles[i].parent.constructor.name == "ParagraphStyleGroup") myParStylesList[i]+=" ["+myStyles[i].parent.name+"]";
}
//---------------------------------------------------------
//Adding Obejct Styles with Sub Groups
//---------------------------------------------------------
var mydoc = app.activeDocument;
myStyles = mydoc.allObjectStyles;
var myObjStylesList = [];
for (i = 0; i < myStyles.length; i ++){
myObjStylesList[i] = myStyles[i].name;
if (myStyles[i].parent.constructor.name == "ObjectStyleGroup") myObjStylesList[i]+=" ["+myStyles[i].parent.name+"]";
}
after that (all the three) - (myCharsStyles-myParStylesList-myObjStylesList),ofcourse i know its an Arrays (not list) but it just a name, so all the three arrays are calleb in the script UI like that :
//Adding the Character Styles Found
myDropDownInside.add ("statictext", undefined, "Character styles :");
myDropDownInside.alignment = "center";
var myDropdown1 = myDropDownInside.add ("dropdownlist", undefined, myCharsStyles);
myDropdown1.preferredSize.width = 182;
myDropdown1.selection = 0 ;
//DropDown Visibiliy
myDropdown1.visible = true;
//Adding the Paragraph Styles Found
myDropDownInside.add ("statictext", undefined, "Paragraph styles :");
myDropDownInside.alignment = "center";
var myDropdown2 = myDropDownInside.add ("dropdownlist", undefined, myParStylesList);
myDropdown2.preferredSize.width = 182;
myDropdown2.selection = 0 ;
//DropDown Visibiliy
myDropdown2.visible = false;
//Adding the Object Styles Found
myDropDownInside.add ("statictext", undefined, "Object styles :");
myDropDownInside.alignment = "center";
var myDropdown3 = myDropDownInside.add ("dropdownlist", undefined, myObjStylesList);
myDropdown3.preferredSize.width = 182;
myDropdown3.selection = 0 ;
//DropDown Visibiliy
myDropdown3.visible = false;
and after that i let the user hit the find button to (find a grep) and apply the styles, like that :
function CharStyleGREP() {
var myCStyles = myDropdown1.selection.toString();
//var myCStyles = myDropdown1.selection.textselection();
//Show ProgressBar
w.prg.visible = true;
var myDoc = app.activeDocument
app.findGrepPreferences.findWhat = myGREPString.text;
if(app.activeDocument.characterStyles.itemByName(myCStyles).isValid == true)
app.changeGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyleGroups.itemByName(myCStyles);
//app.changeGrepPreferences.appliedCharacterStyle = myCStyles
for(i=0;i<myDoc.pages.length;i++){
myDoc.changeGrep();
w.prg.value ++
}
w.prg.visible = false;
}
function ParaStyleGREP() {
//Start the function-myDropDown 2
var myPStyles = myDropdown2.selection.toString();
//Show ProgressBar
w.prg.visible = true;
var myDoc = app.activeDocument
app.findGrepPreferences.findWhat = myGREPString.text;
app.changeGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.itemByName(myPStyles);
for(i=0;i<myDoc.pages.length;i++){
myDoc.changeGrep();
w.prg.value ++
}
w.prg.visible = false;
}
//Execute Object Style GREP
function ObjStyleGREP() {
//Show ProgressBar
w.prg.visible = true;
//Start the function
var myObjectStyle = myDropdown3.selection.toString(); //Object Style from DropDown List
var GrepString= myGREPString.text
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = GrepString;
myFoundText = app.activeDocument.findGrep();
for(i=0;i<myFoundText.length;i++){
myFoundText[i].parentTextFrames[0].appliedObjectStyle=app.activeDocument.objectStyles.itemByName(myObjectStyle);
//ProgressBar Start Count
w.prg.value ++;
}
//Hide ProgressBar afterFinish
w.prg.visible = false;
}
so the problem is the script only works on the styles in the root, not apply any styles in (groups), so please how to fix that? and thanks in advance
Hi M.Hasanain,
there is a allParagraphStyles array and a allCharacterStyles array with every document.
The order of the stored styles there reflect the order of all styles in the respective Paragraph Styles panel or the Character Styles panel in InDesign's native UI.
If you build your drop down list from the allParagraphStyles array, you simply need the index of the list item the user selects; because that corresponds with the stored style in the allParagraphStyles array or in the allCharacter
...Copy link to clipboard
Copied
Hi M.Hasanain,
there is a allParagraphStyles array and a allCharacterStyles array with every document.
The order of the stored styles there reflect the order of all styles in the respective Paragraph Styles panel or the Character Styles panel in InDesign's native UI.
If you build your drop down list from the allParagraphStyles array, you simply need the index of the list item the user selects; because that corresponds with the stored style in the allParagraphStyles array or in the allCharacterStyles array. Then you could use:
appliedParagraphStyle = doc.allParagraphStyles[n]
Where variable n in my line above holds the index of the selected list item:
myDropdown1.selection.index
This should work then:
appliedParagraphStyle = doc.allParagraphStyles[ myDropdown1.selection.index ]
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Thank you a lot, the idea of index or id came to my mind but i was stack and not imagined the solution, thanks a lot again
Copy link to clipboard
Copied
where does this fixed code go? I have the same issue with my script not grabbing the styles in folders and i cant figure out where to put this code to get it to work.