Copy link to clipboard
Copied
Greetings to you! Help me fix the error in the script. He should create captions to photos, apply the paragraph style selected in the dialog box and indent from the photo. The error most likely lies in reading the selected paragraph style from the drop-down list, because everything works correctly without this part of the code.
Here is the code itself (there are a lot of words in Russian, do not be afraid):
Hi vistarmedia@gmail.com , Here’s an example for getting a paragraph style from a dropdown:
makeDialog();
var psSel;
function makeDialog(){
var theDialog = app.dialogs.add({name:"Dialog Components", canCancel:true});
with(theDialog){
with(dialogColumns.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Paragraph Styles:"});
}
with(dialogColumns.add()){
psSel = dropdowns.add(
...
Copy link to clipboard
Copied
Hi vistarmedia@gmail.com , Here’s an example for getting a paragraph style from a dropdown:
makeDialog();
var psSel;
function makeDialog(){
var theDialog = app.dialogs.add({name:"Dialog Components", canCancel:true});
with(theDialog){
with(dialogColumns.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Paragraph Styles:"});
}
with(dialogColumns.add()){
psSel = dropdowns.add({stringList:getArrayNames(app.activeDocument.allParagraphStyles), selectedIndex:0, minWidth:80});
}
}
if(theDialog.show() == true){
psSel = app.activeDocument.allParagraphStyles[psSel.selectedIndex];
main();
theDialog.destroy();
}
}
}
function main(){
alert("\rChosen Paragraph Style: " + psSel.name);
}
/**
* Returns a list of style names from the provided array of styles.
* Note does not work with a collection allParagraphStyles is an array paragraphStyles is a collection
* @ param the object array
* @ return array of names
*/
function getArrayNames(arr){
var a = new Array;
for(var i = 0; i < arr.length; i++){
a.push(arr[i].name);
}
return a
}
Copy link to clipboard
Copied
Thank you very much! for some reason, InDesign was giving an error referring to this code snippet with a drop-down list. Specifically on getArrayNames.
Then I replaced this line with this one (I have paragraph styles nested in a group):
var selectedStyle = dropdowns.add({stringList: app.activeDocument.paragraphStyleGroups.item(0).paragraphStyles.everyItem().name, selectedIndex: 0});
And then everything worked as it should!
Thanks again! You solved a problem I've been working on for almost a week in an instant)
Copy link to clipboard
Copied
Just note in case you don’t know—you can get all of the document’s paragraph style, grouped or not, via the .allParagraphStyles property. It returns an array, not a collection, which is why I included the getArrayNames function in my code—you would have to add the same function to your script. Your code would get an array of paragraph styles in the document’s first group, but not from other groups.
For example with this style setup:
//Returns Group 1 styles ID Default,body
$.writeln(app.activeDocument.paragraphStyleGroups.item(0).paragraphStyles.everyItem().name)
While this gets all of the styles:
$.writeln(getArrayNames(app.activeDocument.allParagraphStyles))
//returns [No Paragraph Style],[Basic Paragraph],Caption Text,Foot,Text,Logo,SubLogo,ID Default,body
/**
* Returns a list of style names from the provided array of styles.
* Note does not work with a collection allParagraphStyles is an array paragraphStyles is a collection
* @ param the object array
* @ return array of names
*/
function getArrayNames(arr){
var a = new Array;
for(var i = 0; i < arr.length; i++){
a.push(arr[i].name);
}
return a
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now