Table error - invalid parameter

New Here ,
Jul 22, 2022 Jul 22, 2022

Copy link to clipboard

Copied

Hi Friends,

 

The below scripts provided by "vinny38", when i run the script its showing "invalid parameter" error, please see the screen shot below, i am beginner of this platform, anybody can guide to me:

 

invalid parameter.png

 

-----------------------------------------------------

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.k

 

 

 

TOPICS
Scripting

Views

153

Likes

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 2 Correct answers

Adobe Community Professional , Jul 22, 2022 Jul 22, 2022

This line at the top should be 

        myStylesNames.push(myDocument.allParagraphStyles[i].name);

 

It's missing the [i] iterator. Old code on the forum was stripped of those iterators when the forums moved to a new platform a while back. 

 

Likes

Translate

Translate
Adobe Community Professional , Jul 25, 2022 Jul 25, 2022

Hi @kanagakumar,

The script works for me. See a demo of it working in the video below

Infact looking the discussion here, it seems the find replace in the script is also not needed in the script. So the following script also works.

if (app.documents.length > 0) {
    var myDocument = app.documents[0];
    //----------------------------Open Dialog box----------------------------//
    var myStylesNames = [];
    for (i = 0; i < myDocument.allParagraphStyles.length; i++) {
        myStylesNames.p
...

Likes

Translate

Translate
Adobe Community Professional ,
Jul 22, 2022 Jul 22, 2022

Copy link to clipboard

Copied

This line at the top should be 

        myStylesNames.push(myDocument.allParagraphStyles[i].name);

 

It's missing the [i] iterator. Old code on the forum was stripped of those iterators when the forums moved to a new platform a while back. 

 

Likes

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
New Here ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

Thank you "brianp311",

The above mentiond code added, and running. And its stoped another place, script showing another error "undefined is not an object". This error place i have marked and post the screen shot below, kindly suggest:

 

undefined is not an object.png

Thanks

kanagakumar.k

 

 

 

Likes

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
New Here ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

Dear "brianp311",

Please see below my table paragraph style screen shot for your reference, script asking style name, I choose the "TB" style, after that its stop the script and showing the above mentioned error "undefined is not an object", please advice:

TB style.png

Thanks

kanagakumar.k

Likes

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
Adobe Community Professional ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

Its again the same issue that @brianp311 pointed to before. Change the code to the following

 if (allText[i].appliedParagraphStyle.name == myParaStyle) {
   myText.push(allText[i]);
}

There is same error again in the for loop that follows this code. Change it to the following

for (var i = 0; i < myText.length; i++) {
        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;
}

Hopefully with these two changes the script will work.

-Manan

Likes

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
New Here ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

Deear Manan Joshi,

Thank you for your coding:

Your provided coding running successfully with out error but i cannot identify the what changes made in this code.

Also center alignment is not updated in the column (unit alignment with center of the column)

Please advice.

 

Thanks

kanagakumar.k

Likes

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
Adobe Community Professional ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

Hi @kanagakumar,

I am not sure what this script is meant to do. Where did you get this script from? Instead of me reading and understanding what the script is supposed to do, please share the source of the script and then an example of what you expect from the script and what it is doing, this would save time for both of us.

-Manan

Likes

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
New Here ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

Dear Manan,

This is source script defined by "vinny38":

--------------------------------------------------

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.k

Likes

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
Adobe Community Professional ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Hi @kanagakumar,

The script works for me. See a demo of it working in the video below

Infact looking the discussion here, it seems the find replace in the script is also not needed in the script. So the following script also works.

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();
    //---------------------------- 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[i]);
        }
    }
    //---------------------------- 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[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");
}

-Manan

Likes

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
New Here ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Thank you very much "Manan"

 

This script working fine but some column not align center, kindly see the screen shot blow  yellow color highlighting, can you suggest on this:

 

column alignment.png

Thanks

kanagakumar.k

Likes

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
Adobe Community Professional ,
Jul 26, 2022 Jul 26, 2022

Copy link to clipboard

Copied

LATEST

Hi @kanagakumar ,

Align Center is a property of the paragraph.

Perhaps the alignment now switched to "center", but optically it is not, because other formatting will not allow this. Like there are indents for the paragraph defined or there are tabs in the text or the tab is set to the decimal dot.

 

The task is more difficult as you might see at first glance. And that would require a different script that is way more complicated to write than the one you are currently running.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Likes

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