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

Error: Expected ParagraphStyle or String, but received "Drop Style 2 "

Participant ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

Hi everyone,
I am improving my script with dropdownlist and now I am receiving this message:

Error:
Expected ParagraphStyle or String, but received "Drop Style 2 "

"Drop Style 2" is paragraph style.
What am I doing wrong?
Please any help would be great.

The complet script:

function buildList (scope, list, str) {
var temp;
var styles = scope.paragraphStyles.everyItem().getElements();
for (var i = 0; i < styles.length; i++) {
temp = list.add ('item', styles[i].name + (str == ' ' ? ' ' : ' ('+str+')'));
temp.id = styles[i].id; // Add property so we can easily get a handle on the style later
}
for (var j = 0; j < scope.paragraphStyleGroups.length; j++) {
buildList (scope.paragraphStyleGroups[j], list, scope.paragraphStyleGroups[j].name+(str == ' ' ? ' ' : ':') + str);
}
}

var dialog = new Window("dialog", undefined, undefined, {maximizeButton: true, independent: true});
dialog.text = "Dropword";
dialog.preferredSize.width = 350;
dialog.preferredSize.height = 350;
dialog.orientation = "column";
dialog.alignChildren = ["center","top"];
dialog.spacing = 10;
dialog.margins = 16;

// PANEL1
// ======
var panel1 = dialog.add("panel", undefined, undefined, {name: "panel1"});
panel1.text = "Paragraph Style";
panel1.preferredSize.width = 300;
panel1.preferredSize.height = 53;
panel1.orientation = "column";
panel1.alignChildren = ["left","top"];
panel1.spacing = 10;
panel1.margins = 10;

panel1.pstyles = panel1.add ('dropdownlist');
buildList (app.activeDocument, panel1.pstyles, ' ');
panel1.pstyles.remove (panel1.pstyles.items[0]); // Remove [No Paragraph]
panel1.pstyles.selection = 0;


//PANEL2
//======
var panel2 = dialog.add("panel", undefined, undefined, {name: "panel2"});
panel2.text = "número de linhas";
panel2.preferredSize.width = 144;
panel2.preferredSize.height = 53;
panel2.orientation = "column";
panel2.alignChildren = ["left","top"];
panel2.spacing = 10;
panel2.margins = 10;

var edittext2 = panel2.add('edittext {properties: {name: "edittext2"}}');
edittext2.text = "2";
edittext2.preferredSize.width = 50;

// PANEL3
// ======
var panel3 = dialog.add("panel", undefined, undefined, {name: "panel3"});
panel3.text = "número de palavras";
panel3.preferredSize.width = 150;
panel3.preferredSize.height = 53;
panel3.orientation = "column";
panel3.alignChildren = ["left","top"];
panel3.spacing = 10;
panel3.margins = 10;

var edittext3 = panel3.add('edittext {properties: {name: "edittext3"}}');
edittext3.text = "1";
edittext3.preferredSize.width = 50;
edittext3.preferredSize.height = 23;

// PANEL4
// ======
var panel4 = dialog.add("panel", undefined, undefined, {name: "panel4"});
panel4.text = "estilo para apenas 1 linha";
panel4.preferredSize.width = 150;
panel4.preferredSize.height = 53;
panel4.orientation = "column";
panel4.alignChildren = ["left","top"];
panel4.spacing = 10;
panel4.margins = 10;

var edittext4 = panel4.add('edittext {properties: {name: "edittext4", multiline: true}}');
edittext4.text = "1 line";
edittext4.preferredSize.width = 290;
edittext4.preferredSize.height = 23;

// PANEL5
// ======
var panel5 = dialog.add("panel", undefined, undefined, {name: "panel5"});
panel5.text = "estilo para 1 linha com até 2 palavras";
panel5.preferredSize.width = 150;
panel5.preferredSize.height = 53;
panel5.orientation = "column";
panel5.alignChildren = ["left","top"];
panel5.spacing = 10;
panel5.margins = 10;

var edittext5 = panel5.add('edittext {properties: {name: "edittext5", multiline: true}}');
edittext5.text = "Center";
edittext5.preferredSize.width = 290;
edittext5.preferredSize.height = 23;

var convert_button = dialog.add ("button", undefined, "OK");

convert_button.onClick = function () {
e.text = panel1.pstyles.selection.text;
edittext2.text;
edittext3.text;
edittext4.text;
edittext5.text;
}

dialog.show ();

$.bp()


var teste = panel1.pstyles.selection.text;
// Style name
var dsName = teste

// number of lines for the dropcap height
var lcnt = edittext2.text

// number of words to dropcap
var wcnt = edittext3.text

var myParas = app.selection[0].paragraphs,
P = myParas.length,
p;

for ( var p = 0; p < P; p++ )
if ( myParas[p].lines.length > 1 )
myParas[p].appliedParagraphStyle = String (teste);

var myParas = app.selection[0].paragraphs,
P = myParas.length,
p;

for ( var p = 0; p < P; p++ )
if ( myParas[p].lines.length < 2 )
if ( myParas[p].words.length >= 3 )
myParas[p].appliedParagraphStyle = edittext4.text ;

var myParas = app.selection[0].paragraphs, P = myParas.length, p; for ( var p = 0; p < P; p++ )
if ( myParas[p].words.length <= 2 ) myParas[p].appliedParagraphStyle = edittext5.text ;

var ds = app.selection[0].paragraphs
for(var i=0; i < ds.length; i++){
var p=ds.item(i);
if (p.appliedParagraphStyle.name == dsName && p.lines.length > lcnt-1) {
var dc = p.words.itemByRange(p.words[0], p.words[wcnt-1]);
p.dropCapCharacters = dc.characters.length+1
if (ds.item[0] == Number, dc.characters.length+3); {
p.dropCapLines = Number (lcnt);
}
}
}

TOPICS
Scripting

Views

160

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

correct answers 1 Correct answer

Community Expert , Mar 18, 2021 Mar 18, 2021

A lot of code to sift through, but your error message shows an extra space after 2 in the quotes: 

Expected ParagraphStyle or String, but received "Drop Style 2 "

 

If the style is "Drop Style 2", then that extra space will fail. I'd focus my debugging efforts there. I'd also pass the string to a create a paragraphStyle object and pass it that, and validate the object that way. 

Votes

Translate

Translate
Community Expert ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

A lot of code to sift through, but your error message shows an extra space after 2 in the quotes: 

Expected ParagraphStyle or String, but received "Drop Style 2 "

 

If the style is "Drop Style 2", then that extra space will fail. I'd focus my debugging efforts there. I'd also pass the string to a create a paragraphStyle object and pass it that, and validate the object that way. 

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
Participant ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

Thank You @brianp311,
I am trying to find the error but is difiicult for me.
Regards
Sami

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
Participant ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

LATEST

Hi @brianp311 brianp311,
You are right!

The dropdownlist always gives you an extra space

The solution was add slice:

.slice (0, -1)
Best regards
Sami

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