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

What is the error meaning?

Participant ,
Jul 17, 2022 Jul 17, 2022

Copy link to clipboard

Copied

Dear All,

The below script provided by "vinny38", when i run the below script "Undefined is not an abject error" showing, i am new in the script platform. How to clear the run time error? please advice

 

if (app.documents.length > 0) {

var myDocument = app.documents[0];

//----------------------------Open Dialog box----------------------------//

var myStylesNames = [];

for (i = 0; i < myDocument.allParagraphStyles.length; i++) {

myStylesNames.push(myDocument.allParagraphStyles.name);

}

var myDialog = app.dialogs.add({

name: "Align to dots script",

canCancel: true

});

with(myDialog.dialogColumns.add()) {

staticTexts.add({

staticLabel: "Choose the paragraph style applied to the cells you want to align on dot"

});

}

with(myDialog.dialogColumns.add()) {

var myDDSTyles = dropdowns.add({

stringList: myStylesNames,

selectedIndex: 0

});

}

var myResult = myDialog.show();

if (myResult == true) {

var myParaStyle = myStylesNames[myDDSTyles.selectedIndex];

}

myDialog.destroy();

//---------------------------- add a tab before (if doesn't exist) ----------------------------//

app.findGrepPreferences = null;

app.changeGrepPreferences = null;

app.findGrepPreferences.properties = {

findWhat: "^(\\d)",

appliedParagraphStyle: myParaStyle,

}

app.changeGrepPreferences.changeTo = "\\t$1";

app.activeDocument.changeGrep();

app.findGrepPreferences = null;

app.changeGrepPreferences = null;

//---------------------------- create array ----------------------------//

var myText = [];

var allText = myDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().getElements();

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

if (allText.appliedParagraphStyle.name == myParaStyle) {

myText.push(allText);

}

}

//---------------------------- Set tab alignment and apply to cells ----------------------------//

var tabStopProperties = {

alignment: TabStopAlignment.CHARACTER_ALIGN,

alignmentCharacter: "."

};

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

var cellWidth = myText.parent.width;

var cellLeftInset = myText.parent.leftInset;

var cellRightInset = myText.parent.rightInset;

var position = (cellWidth - cellRightInset - cellLeftInset - 1.058) / 2;

myText.tabStops.everyItem().remove();

myText.tabStops.add();

myText.tabStops[0].properties = tabStopProperties;

myText.tabStops[0].position = position;

}

} else {

alert("Please open a document");

}

 

Thanks

kanagakumar

TOPICS
Scripting

Views

208

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 , Jul 18, 2022 Jul 18, 2022

They'll still have to select InDesign as the target application 🙂

Votes

Translate

Translate
Participant ,
Jul 18, 2022 Jul 18, 2022

Copy link to clipboard

Copied

Please see the screen shot blow:

 

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 ,
Jul 18, 2022 Jul 18, 2022

Copy link to clipboard

Copied

In the top left of your screen you see a dropdown in which 'ExtendScript Toolkit CC' is selected. You should select your InDesign version in that dropdown.

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 ,
Jul 18, 2022 Jul 18, 2022

Copy link to clipboard

Copied

They'll still have to select InDesign as the target application 🙂

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 ,
Jul 18, 2022 Jul 18, 2022

Copy link to clipboard

Copied

Hi @kanagakumar, I managed to get it up and running with a few tweaks. Probably was corrupted by text formatting. Also was missing a check for undefined myText[i]. - Mark

 

if (app.documents.length > 0) {
    var myDocument = app.documents[0];
    //----------------------------Open Dialog box----------------------------//
    var myStylesNames = [];
    for (i = 0; i < myDocument.allParagraphStyles.length; i++) {
        myStylesNames.push(myDocument.allParagraphStyles[i].name);
    }
    var myDialog = app.dialogs.add({
        name: "Align to dots script",
        canCancel: true
    });
    with (myDialog.dialogColumns.add()) {
        staticTexts.add({
            staticLabel: "Choose the paragraph style applied to the cells you want to align on dot"
        });
    }

    with (myDialog.dialogColumns.add()) {
        var myDDSTyles = dropdowns.add({
            stringList: myStylesNames,
            selectedIndex: 0
        });
    }
    var myResult = myDialog.show();
    if (myResult == true) {
        var myParaStyle = myStylesNames[myDDSTyles.selectedIndex];
    }
    myDialog.destroy();
    //---------------------------- add a tab before (if doesn't exist) ----------------------------//
    app.findGrepPreferences = null;
    app.changeGrepPreferences = null;
    app.findGrepPreferences.properties = {
        findWhat: "^(\\d)",
        appliedParagraphStyle: myParaStyle,
    }
    app.changeGrepPreferences.changeTo = "\\t$1";
    app.activeDocument.changeGrep();
    app.findGrepPreferences = null;
    app.changeGrepPreferences = null;
    //---------------------------- create array ----------------------------//
    var myText = [];
    var allText = myDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().getElements();
    for (i = 0; i < allText.length; i++) {
        if (allText[i].appliedParagraphStyle.name == myParaStyle) {
            myText.push(allText);
        }
    }
    //---------------------------- Set tab alignment and apply to cells ----------------------------//
    var tabStopProperties = {
        alignment: TabStopAlignment.CHARACTER_ALIGN,
        alignmentCharacter: "."
    };
    for (var i = 0; i < myText.length; i++) {

        if (myText[i].parent == undefined)continue;
        var cellWidth = myText[i].parent.width;
        var cellLeftInset = myText[i].parent.leftInset;
        var cellRightInset = myText[i].parent.rightInset;
        var position = (cellWidth - cellRightInset - cellLeftInset - 1.058) / 2;
        myText[i].tabStops.everyItem().remove();
        myText[i].tabStops.add();
        myText[i].tabStops[0].properties = tabStopProperties;
        myText[i].tabStops[0].position = position;
    }
} else {
    alert("Please open a document");
}

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 ,
Jul 18, 2022 Jul 18, 2022

Copy link to clipboard

Copied

Also shout out to @vinny38 for the original script! 🙂

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 ,
Jul 18, 2022 Jul 18, 2022

Copy link to clipboard

Copied

They'll still have to select InDesign as the target application 🙂

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 ,
Jul 18, 2022 Jul 18, 2022

Copy link to clipboard

Copied

LATEST

Thank you Peter Kahrel

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