Highlighted

Groups aren't being created in the desired order

Community Beginner ,
Feb 22, 2020

Copy link to clipboard

Copied

I have a page which looks similar to the following in the Layers tab:

 

Text

   Text Frame 1

   Text Frame 2

   Text Frame 3

 

I wrote a script which prompts the user for several pieces of information, and takes that information to create a group.  For example, the user enters "Text Frame 1", "Text Frame 2", and a group name we will call "Fred".

 

When the script finishes, all of my pages on the Layers tab look like:

 

Text

   > Fred

   Text Frame 3

 

If you expand Fred, you see:

 

Text

   Fred

      Text Frame 1

      Text Frame 2

  Text Frame 3

 

All well and good.  If, however, the user enters the data "Text Frame 2", "Text Frame 1", and "Fred", I expect to see:

 

Text

   Fred

      Text Frame 2

      Text Frame 1

   Text Frame 3

 

Unfortunately, I still see it as it appears in example 1.  I have confirmed that when the array is created, it is in the proper order.  But when the group is created, it is always created in the original order of the listed frames in the Layers Text section.  If I swap Text Frame 1 and Text Frame 2 in the original order, the group is then created correctly.

 

There must be a way to create a group with frames in the order I desire them.  What am I missing?

Adobe Community Professional
Correct answer by Sunil_Yadav1 | Adobe Community Professional

Instead of prompts why don't you try ScriptUI:

Screen.png

 

// DIALOG
// ======
var dialog = new Window("dialog"); 
    dialog.text = "Match Object & Move"; 
    dialog.preferredSize.width = 300; 
    dialog.preferredSize.height = 300; 
    dialog.orientation = "column"; 
    dialog.alignChildren = ["center","top"]; 
    dialog.spacing = 10; 
    dialog.margins = 16; 

// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"}); 
    group1.preferredSize.width = 270; 
    group1.orientation = "row"; 
    group1.alignChildren = ["left","center"]; 
    group1.spacing = 10; 
    group1.margins = [0,0,0,11]; 

var statictext1 = group1.add("statictext", undefined, undefined, {name: "statictext1"}); 
    statictext1.text = "Find Object with specific value & change"; 

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

// GROUP2
// ======
var group2 = panel1.add("group", undefined, {name: "group2"}); 
    group2.orientation = "row"; 
    group2.alignChildren = ["left","center"]; 
    group2.spacing = 10; 
    group2.margins = 0; 

// GROUP3
// ======
var group3 = group2.add("group", undefined, {name: "group3"}); 
    group3.preferredSize.width = 110; 
    group3.orientation = "row"; 
    group3.alignChildren = ["left","center"]; 
    group3.spacing = 10; 
    group3.margins = 0; 

var statictext2 = group3.add("statictext", undefined, undefined, {name: "statictext2"}); 
    statictext2.text = "X :"; 
    statictext2.preferredSize.width = 20; 

var edittext1 = group3.add('edittext {properties: {name: "edittext1"}}'); 
    edittext1.text = "0"; 
    edittext1.preferredSize.width = 60; 
    edittext1.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP4
// ======
var group4 = group2.add("group", undefined, {name: "group4"}); 
    group4.orientation = "row"; 
    group4.alignChildren = ["left","center"]; 
    group4.spacing = 10; 
    group4.margins = 0; 

var statictext3 = group4.add("statictext", undefined, undefined, {name: "statictext3"}); 
    statictext3.text = "W :"; 
    statictext3.preferredSize.width = 20; 

var edittext2 = group4.add('edittext {properties: {name: "edittext2"}}'); 
    edittext2.text = "0"; 
    edittext2.preferredSize.width = 60; 
    edittext2.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP5
// ======
var group5 = panel1.add("group", undefined, {name: "group5"}); 
    group5.orientation = "row"; 
    group5.alignChildren = ["left","center"]; 
    group5.spacing = 10; 
    group5.margins = 0; 

// GROUP6
// ======
var group6 = group5.add("group", undefined, {name: "group6"}); 
    group6.preferredSize.width = 110; 
    group6.orientation = "row"; 
    group6.alignChildren = ["left","center"]; 
    group6.spacing = 10; 
    group6.margins = 0; 

var statictext4 = group6.add("statictext", undefined, undefined, {name: "statictext4"}); 
    statictext4.text = "Y : "; 
    statictext4.preferredSize.width = 20; 

var edittext3 = group6.add('edittext {properties: {name: "edittext3"}}'); 
    edittext3.text = "0"; 
    edittext3.preferredSize.width = 60; 
    edittext3.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP7
// ======
var group7 = group5.add("group", undefined, {name: "group7"}); 
    group7.orientation = "row"; 
    group7.alignChildren = ["left","center"]; 
    group7.spacing = 10; 
    group7.margins = 0; 

var statictext5 = group7.add("statictext", undefined, undefined, {name: "statictext5"}); 
    statictext5.text = "H : "; 

var edittext4 = group7.add('edittext {properties: {name: "edittext4"}}'); 
    edittext4.text = "0"; 
    edittext4.preferredSize.width = 60; 
    edittext4.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// DIALOG
// ======
var divider1 = dialog.add("panel", undefined, undefined, {name: "divider1"}); 
    divider1.alignment = "fill"; 

// GROUP8
// ======
var group8 = dialog.add("group", undefined, {name: "group8"}); 
    group8.preferredSize.width = 270; 
    group8.orientation = "row"; 
    group8.alignChildren = ["left","center"]; 
    group8.spacing = 10; 
    group8.margins = 0; 

var checkbox1 = group8.add("checkbox", undefined, undefined, {name: "checkbox1"}); 
    checkbox1.text = "Change the object with values : "; 
    checkbox1.onClick = function (){
        group9.enabled = this.value;
        group12.enabled = this.value;
        button1.enabled = this.value;
        if(this.value){
            edittext5.text = edittext1.text;
            edittext6.text = edittext2.text;
            edittext7.text = edittext3.text;
            edittext8.text = edittext4.text;
            }
        else{
            edittext5.text = "";
            edittext6.text = "";
            edittext7.text = "";
            edittext8.text = "";
            }
        }

// PANEL2
// ======
var panel2 = dialog.add("panel", undefined, undefined, {name: "panel2"}); 
    panel2.text = "Change Object"; 
    panel2.preferredSize.width = 270; 
    panel2.preferredSize.height = 100; 
    panel2.orientation = "column"; 
    panel2.alignChildren = ["left","top"]; 
    panel2.spacing = 10; 
    panel2.margins = 10; 

// GROUP9
// ======
var group9 = panel2.add("group", undefined, {name: "group9"}); 
    group9.enabled = false; 
    group9.orientation = "row"; 
    group9.alignChildren = ["left","center"]; 
    group9.spacing = 10; 
    group9.margins = 0; 

// GROUP10
// =======
var group10 = group9.add("group", undefined, {name: "group10"}); 
    group10.preferredSize.width = 110; 
    group10.orientation = "row"; 
    group10.alignChildren = ["left","center"]; 
    group10.spacing = 10; 
    group10.margins = 0; 

var statictext6 = group10.add("statictext", undefined, undefined, {name: "statictext6"}); 
    statictext6.text = "X : "; 

var edittext5 = group10.add('edittext {properties: {name: "edittext5"}}'); 
    edittext5.preferredSize.width = 60; 
    edittext5.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP11
// =======
var group11 = group9.add("group", undefined, {name: "group11"}); 
    group11.orientation = "row"; 
    group11.alignChildren = ["left","center"]; 
    group11.spacing = 10; 
    group11.margins = 0; 

var statictext7 = group11.add("statictext", undefined, undefined, {name: "statictext7"}); 
    statictext7.text = "W : "; 

var edittext6 = group11.add('edittext {properties: {name: "edittext6"}}'); 
    edittext6.preferredSize.width = 60; 
    edittext6.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP12
// =======
var group12 = panel2.add("group", undefined, {name: "group12"}); 
    group12.enabled = false; 
    group12.orientation = "row"; 
    group12.alignChildren = ["left","center"]; 
    group12.spacing = 10; 
    group12.margins = 0; 

// GROUP13
// =======
var group13 = group12.add("group", undefined, {name: "group13"}); 
    group13.preferredSize.width = 110; 
    group13.orientation = "row"; 
    group13.alignChildren = ["left","center"]; 
    group13.spacing = 10; 
    group13.margins = 0; 

var statictext8 = group13.add("statictext", undefined, undefined, {name: "statictext8"}); 
    statictext8.text = "Y : "; 

var edittext7 = group13.add('edittext {properties: {name: "edittext7"}}'); 
    edittext7.preferredSize.width = 60; 
    edittext7.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP14
// =======
var group14 = group12.add("group", undefined, {name: "group14"}); 
    group14.orientation = "row"; 
    group14.alignChildren = ["left","center"]; 
    group14.spacing = 10; 
    group14.margins = 0; 

var statictext9 = group14.add("statictext", undefined, undefined, {name: "statictext9"}); 
    statictext9.text = "H : "; 

var edittext8 = group14.add('edittext {properties: {name: "edittext8"}}'); 
    edittext8.preferredSize.width = 60; 
    edittext8.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP15
// =======
var group15 = dialog.add("group", undefined, {name: "group15"}); 
    group15.preferredSize.width = 270; 
    group15.orientation = "row"; 
    group15.alignChildren = ["right","center"]; 
    group15.spacing = 10; 
    group15.margins = 0; 

var button1 = group15.add("button", undefined, undefined, {name: "button1"}); 
    button1.text = "Apply"; 
    button1.enabled = false;

var button2 = group15.add("button", undefined, undefined, {name: "button2"}); 
    button2.text = "Cancel"; 

if(dialog.show() == 1){
    $.bp();
    // Here you can put your execution code ///
    }

 

Best

Sunil

Topics

Scripting

Views

516

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

Groups aren't being created in the desired order

Community Beginner ,
Feb 22, 2020

Copy link to clipboard

Copied

I have a page which looks similar to the following in the Layers tab:

 

Text

   Text Frame 1

   Text Frame 2

   Text Frame 3

 

I wrote a script which prompts the user for several pieces of information, and takes that information to create a group.  For example, the user enters "Text Frame 1", "Text Frame 2", and a group name we will call "Fred".

 

When the script finishes, all of my pages on the Layers tab look like:

 

Text

   > Fred

   Text Frame 3

 

If you expand Fred, you see:

 

Text

   Fred

      Text Frame 1

      Text Frame 2

  Text Frame 3

 

All well and good.  If, however, the user enters the data "Text Frame 2", "Text Frame 1", and "Fred", I expect to see:

 

Text

   Fred

      Text Frame 2

      Text Frame 1

   Text Frame 3

 

Unfortunately, I still see it as it appears in example 1.  I have confirmed that when the array is created, it is in the proper order.  But when the group is created, it is always created in the original order of the listed frames in the Layers Text section.  If I swap Text Frame 1 and Text Frame 2 in the original order, the group is then created correctly.

 

There must be a way to create a group with frames in the order I desire them.  What am I missing?

Adobe Community Professional
Correct answer by Sunil_Yadav1 | Adobe Community Professional

Instead of prompts why don't you try ScriptUI:

Screen.png

 

// DIALOG
// ======
var dialog = new Window("dialog"); 
    dialog.text = "Match Object & Move"; 
    dialog.preferredSize.width = 300; 
    dialog.preferredSize.height = 300; 
    dialog.orientation = "column"; 
    dialog.alignChildren = ["center","top"]; 
    dialog.spacing = 10; 
    dialog.margins = 16; 

// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"}); 
    group1.preferredSize.width = 270; 
    group1.orientation = "row"; 
    group1.alignChildren = ["left","center"]; 
    group1.spacing = 10; 
    group1.margins = [0,0,0,11]; 

var statictext1 = group1.add("statictext", undefined, undefined, {name: "statictext1"}); 
    statictext1.text = "Find Object with specific value & change"; 

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

// GROUP2
// ======
var group2 = panel1.add("group", undefined, {name: "group2"}); 
    group2.orientation = "row"; 
    group2.alignChildren = ["left","center"]; 
    group2.spacing = 10; 
    group2.margins = 0; 

// GROUP3
// ======
var group3 = group2.add("group", undefined, {name: "group3"}); 
    group3.preferredSize.width = 110; 
    group3.orientation = "row"; 
    group3.alignChildren = ["left","center"]; 
    group3.spacing = 10; 
    group3.margins = 0; 

var statictext2 = group3.add("statictext", undefined, undefined, {name: "statictext2"}); 
    statictext2.text = "X :"; 
    statictext2.preferredSize.width = 20; 

var edittext1 = group3.add('edittext {properties: {name: "edittext1"}}'); 
    edittext1.text = "0"; 
    edittext1.preferredSize.width = 60; 
    edittext1.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP4
// ======
var group4 = group2.add("group", undefined, {name: "group4"}); 
    group4.orientation = "row"; 
    group4.alignChildren = ["left","center"]; 
    group4.spacing = 10; 
    group4.margins = 0; 

var statictext3 = group4.add("statictext", undefined, undefined, {name: "statictext3"}); 
    statictext3.text = "W :"; 
    statictext3.preferredSize.width = 20; 

var edittext2 = group4.add('edittext {properties: {name: "edittext2"}}'); 
    edittext2.text = "0"; 
    edittext2.preferredSize.width = 60; 
    edittext2.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP5
// ======
var group5 = panel1.add("group", undefined, {name: "group5"}); 
    group5.orientation = "row"; 
    group5.alignChildren = ["left","center"]; 
    group5.spacing = 10; 
    group5.margins = 0; 

// GROUP6
// ======
var group6 = group5.add("group", undefined, {name: "group6"}); 
    group6.preferredSize.width = 110; 
    group6.orientation = "row"; 
    group6.alignChildren = ["left","center"]; 
    group6.spacing = 10; 
    group6.margins = 0; 

var statictext4 = group6.add("statictext", undefined, undefined, {name: "statictext4"}); 
    statictext4.text = "Y : "; 
    statictext4.preferredSize.width = 20; 

var edittext3 = group6.add('edittext {properties: {name: "edittext3"}}'); 
    edittext3.text = "0"; 
    edittext3.preferredSize.width = 60; 
    edittext3.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP7
// ======
var group7 = group5.add("group", undefined, {name: "group7"}); 
    group7.orientation = "row"; 
    group7.alignChildren = ["left","center"]; 
    group7.spacing = 10; 
    group7.margins = 0; 

var statictext5 = group7.add("statictext", undefined, undefined, {name: "statictext5"}); 
    statictext5.text = "H : "; 

var edittext4 = group7.add('edittext {properties: {name: "edittext4"}}'); 
    edittext4.text = "0"; 
    edittext4.preferredSize.width = 60; 
    edittext4.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// DIALOG
// ======
var divider1 = dialog.add("panel", undefined, undefined, {name: "divider1"}); 
    divider1.alignment = "fill"; 

// GROUP8
// ======
var group8 = dialog.add("group", undefined, {name: "group8"}); 
    group8.preferredSize.width = 270; 
    group8.orientation = "row"; 
    group8.alignChildren = ["left","center"]; 
    group8.spacing = 10; 
    group8.margins = 0; 

var checkbox1 = group8.add("checkbox", undefined, undefined, {name: "checkbox1"}); 
    checkbox1.text = "Change the object with values : "; 
    checkbox1.onClick = function (){
        group9.enabled = this.value;
        group12.enabled = this.value;
        button1.enabled = this.value;
        if(this.value){
            edittext5.text = edittext1.text;
            edittext6.text = edittext2.text;
            edittext7.text = edittext3.text;
            edittext8.text = edittext4.text;
            }
        else{
            edittext5.text = "";
            edittext6.text = "";
            edittext7.text = "";
            edittext8.text = "";
            }
        }

// PANEL2
// ======
var panel2 = dialog.add("panel", undefined, undefined, {name: "panel2"}); 
    panel2.text = "Change Object"; 
    panel2.preferredSize.width = 270; 
    panel2.preferredSize.height = 100; 
    panel2.orientation = "column"; 
    panel2.alignChildren = ["left","top"]; 
    panel2.spacing = 10; 
    panel2.margins = 10; 

// GROUP9
// ======
var group9 = panel2.add("group", undefined, {name: "group9"}); 
    group9.enabled = false; 
    group9.orientation = "row"; 
    group9.alignChildren = ["left","center"]; 
    group9.spacing = 10; 
    group9.margins = 0; 

// GROUP10
// =======
var group10 = group9.add("group", undefined, {name: "group10"}); 
    group10.preferredSize.width = 110; 
    group10.orientation = "row"; 
    group10.alignChildren = ["left","center"]; 
    group10.spacing = 10; 
    group10.margins = 0; 

var statictext6 = group10.add("statictext", undefined, undefined, {name: "statictext6"}); 
    statictext6.text = "X : "; 

var edittext5 = group10.add('edittext {properties: {name: "edittext5"}}'); 
    edittext5.preferredSize.width = 60; 
    edittext5.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP11
// =======
var group11 = group9.add("group", undefined, {name: "group11"}); 
    group11.orientation = "row"; 
    group11.alignChildren = ["left","center"]; 
    group11.spacing = 10; 
    group11.margins = 0; 

var statictext7 = group11.add("statictext", undefined, undefined, {name: "statictext7"}); 
    statictext7.text = "W : "; 

var edittext6 = group11.add('edittext {properties: {name: "edittext6"}}'); 
    edittext6.preferredSize.width = 60; 
    edittext6.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP12
// =======
var group12 = panel2.add("group", undefined, {name: "group12"}); 
    group12.enabled = false; 
    group12.orientation = "row"; 
    group12.alignChildren = ["left","center"]; 
    group12.spacing = 10; 
    group12.margins = 0; 

// GROUP13
// =======
var group13 = group12.add("group", undefined, {name: "group13"}); 
    group13.preferredSize.width = 110; 
    group13.orientation = "row"; 
    group13.alignChildren = ["left","center"]; 
    group13.spacing = 10; 
    group13.margins = 0; 

var statictext8 = group13.add("statictext", undefined, undefined, {name: "statictext8"}); 
    statictext8.text = "Y : "; 

var edittext7 = group13.add('edittext {properties: {name: "edittext7"}}'); 
    edittext7.preferredSize.width = 60; 
    edittext7.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP14
// =======
var group14 = group12.add("group", undefined, {name: "group14"}); 
    group14.orientation = "row"; 
    group14.alignChildren = ["left","center"]; 
    group14.spacing = 10; 
    group14.margins = 0; 

var statictext9 = group14.add("statictext", undefined, undefined, {name: "statictext9"}); 
    statictext9.text = "H : "; 

var edittext8 = group14.add('edittext {properties: {name: "edittext8"}}'); 
    edittext8.preferredSize.width = 60; 
    edittext8.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP15
// =======
var group15 = dialog.add("group", undefined, {name: "group15"}); 
    group15.preferredSize.width = 270; 
    group15.orientation = "row"; 
    group15.alignChildren = ["right","center"]; 
    group15.spacing = 10; 
    group15.margins = 0; 

var button1 = group15.add("button", undefined, undefined, {name: "button1"}); 
    button1.text = "Apply"; 
    button1.enabled = false;

var button2 = group15.add("button", undefined, undefined, {name: "button2"}); 
    button2.text = "Cancel"; 

if(dialog.show() == 1){
    $.bp();
    // Here you can put your execution code ///
    }

 

Best

Sunil

Topics

Scripting

Views

517

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
Adobe Community Professional ,
Feb 23, 2020

Copy link to clipboard

Copied

Hi,
Can you confirm the version of your software and operating system?

Can you also describe what you are trying to achieve? we might be able to offer an alternative approach

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
Reply
Loading...
Community Beginner ,
Feb 23, 2020

Copy link to clipboard

Copied

inDesign 15.0.1. Windows 10 Pro.

 

As the original post states, I have multiple frames that I want to group.  When ever I run my script (see below), it will always group the frames in the ORDER THEY DISPLAY on the Layers tab, even if I place them in an array in a different order.

 

Here is the code I am using:

 

//////////////////////////////////////////////////////////////////////////////////
/// Set key variables to determine what objects are grouped and to set the gorup name
//////////////////////////////////////////////////////////////////////////////////
var nof = prompt("Enter the number of frames to group:", "2");
var ftg = parseInt(nof);
var frameToGroup = [];
var frameXLoc = [];
var frameYLoc = [];
for (var i = 0; i < ftg; i++) {
   var framevalue = prompt("Enter frame to group:", "FrameName");
   frameToGroup.push(framevalue);
   var xlocvalue = prompt("Enter frame x loc value:", "0");
   frameXLoc.push(xlocvalue);
   var ylocvalue = prompt("Enter frame y loc value:", "0");
   frameYLoc.push(ylocvalue);
}
var groupname = prompt("Enter the name of the group to be used:", "GroupName");

 

////////////////////////////////////////////////////////
/// Group objects with a supplied name
////////////////////////////////////////////////////////
var pages = app.activeDocument.pages;
for (var i = 0; i < pages.length; i++) {
   var framesadded = 0;
   var tfs = pages[i].textFrames;
   var arrayToGroup =[];
   for (var k = 0; k < frameToGroup.length; k++) {
      for (var j = 0; j < tfs.length; j++) {
         var frameGB = pages[i].textFrames[j].geometricBounds;
         if (tfs[j].name == frameToGroup[k] && parseFloat(frameGB[1]).toFixed(2) ==   parseFloat(frameXLoc[k]).toFixed(2) && parseFloat(frameGB[0]).toFixed(2) == parseFloat(frameYLoc[k]).toFixed(2)) {
            arrayToGroup.push(tfs[j]);
            framesadded++;
         }
      }
   }

 

   ////////////////////////////////////////////////
   /// Only create the group if all of the frames to be added were found
   ////////////////////////////////////////////////
   if (framesadded == ftg) {
      var group = pages[i].groups.add(arrayToGroup);
      group.name = groupname;
   }
}

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
Reply
Loading...
Engaged ,
Feb 24, 2020

Copy link to clipboard

Copied

Hello any2Cards,

What I suspect you're incounting when the group is added is the text frames are in order of thier creation\stacking order, in spite of the order the information was entered. What I would suggest is to do a reverse loop of the array before creating the group and bring the last item in the loop (first item in the array) "bringToFront" this should put things in the order you're looking for.

 

Reverse loop example:

 

 

 

 

 

        for (var i = arrayToGroup.length-1; i>=0; i--) {
        }

 

 

 

 

 

Regards,

Mike

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
Reply
Loading...
Engaged ,
Feb 24, 2020

Copy link to clipboard

Copied

On second thought you could probably do the reverse loop and "bringToFront" on frameToGroup.length;

 

Regards,

Mike

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
Reply
Loading...
Community Beginner ,
Feb 24, 2020

Copy link to clipboard

Copied

I think you're telling me to perform the reverse loop and bringToFront within this section of the code (before the group is created):

 

if (framesadded == ftg) {
      var group = pages[i].groups.add(arrayToGroup);
      group.name = groupname;
   }

 

But I can't seem to get it to work correctly. Any thoughts/help would be appreciated.

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
Reply
Loading...
Community Beginner ,
Feb 24, 2020

Copy link to clipboard

Copied

I found the following solution.  Not sure if it is the most efficient, but it works:

 

if (framesadded == ftg) {
   var group = pages[i].groups.add(arrayToGroup);
   group.name = groupname;
   for (var j = 0; j < frameToGroup.length ; j++) {
      for (var k = frameToGroup.length-1; k > 0; k--) {
         if (group.allPageItems[j] != arrayToGroup[j]) {
            group.allPageItems[k].bringForward();
         }
      }
   }
}

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
Reply
Loading...
Adobe Community Professional ,
Feb 24, 2020

Copy link to clipboard

Copied

Hi any2cards,

it's a misconception to think that stacking order inside a group is goverened by the order of items in the array.

To change stacking order you could use methods like bringForward() or sendBackward() .

 

FWIW:

Stacking order of elements inside a container object, in this case your group, is the order of elements in this special array:

group.allPageItems . To be precise: First level elements of the container object. Anchored objects for example are not first level objects.

 

A more elaborate idea of moving objects inside a group can be found here:

 

How to add element(s) to an existing group without ungrouping
platm72 | Aug 19, 2019

https://community.adobe.com/t5/indesign/how-to-add-element-s-to-an-existing-group-without-ungrouping...

 

You could start out with a single item group and then add items one by one in the right order.

 

var tmpFrame = textFrame2.duplicate();

// That works if parent of text frame is Object Spread:
textFrame2.parent.groups.add( [ textFrame2 , tmpFrame ] );
tmpFrame.remove();

 

 

Regards,
Uwe Laubender

( ACP )

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
Reply
Loading...
Community Beginner ,
Feb 24, 2020

Copy link to clipboard

Copied

Uwe ...

I read the link you provided, and it seems it is a solution that is way more complicated than what I am trying to do (although the methods used are very interesting).

 

Basically, after my new group is created via script, I simply want to stack the order of the group so that it is in the same order as my arrayToGroup (the items that the user entered).  I have tried the following:

 

if (framesadded == ftg) {
   var group = pages[i].groups.add(arrayToGroup);
   group.name = groupname;
   for (var j = 0; j < frameToGroup.length ; j++) {
      for (var k = 0; k < frameToGroup.length; k++) {
         if (group.allPageItems[j] != arrayToGroup[k]) {
            group.allPageItems[j].sendBackward();
        }
      }
   }
}

 

But this doesn't work.  I can't seem to get the stack order of the final group to match the order of the frames that exist within the array arrayToGroup (which is the order the user entered the information).

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
Reply
Loading...
Community Beginner ,
Feb 24, 2020

Copy link to clipboard

Copied

I found the following solution.  Not sure if it is the most efficient, but it works:

 

if (framesadded == ftg) {
   var group = pages[i].groups.add(arrayToGroup);
   group.name = groupname;
   for (var j = 0; j < frameToGroup.length ; j++) {
      for (var k = frameToGroup.length-1; k > 0; k--) {
         if (group.allPageItems[j] != arrayToGroup[j]) {
            group.allPageItems[k].bringForward();
         }
      }
   }
}

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
Reply
Loading...
Engaged ,
Feb 24, 2020

Copy link to clipboard

Copied

Hi any2Cards,

 

That's kinda what I was tinking with the reverse loop.......did the "bringToFront" not work with that?

 

Regards,

Mike

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
Reply
Loading...
Community Beginner ,
Feb 24, 2020

Copy link to clipboard

Copied

To be honest, I tried so many iterations of different things in the past 2 hours, I can't quite say what did work, didn't work, worked kind of, etc. 😉

 

When I finally got something to work, and then cleaned it up, I was so happy, I just stayed with it.  As I mentioned above, not sure if this is the most efficient way to do it, but it does work.

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
Reply
Loading...
Adobe Community Professional ,
Feb 25, 2020

Copy link to clipboard

Copied

Instead of prompts why don't you try ScriptUI:

Screen.png

 

// DIALOG
// ======
var dialog = new Window("dialog"); 
    dialog.text = "Match Object & Move"; 
    dialog.preferredSize.width = 300; 
    dialog.preferredSize.height = 300; 
    dialog.orientation = "column"; 
    dialog.alignChildren = ["center","top"]; 
    dialog.spacing = 10; 
    dialog.margins = 16; 

// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"}); 
    group1.preferredSize.width = 270; 
    group1.orientation = "row"; 
    group1.alignChildren = ["left","center"]; 
    group1.spacing = 10; 
    group1.margins = [0,0,0,11]; 

var statictext1 = group1.add("statictext", undefined, undefined, {name: "statictext1"}); 
    statictext1.text = "Find Object with specific value & change"; 

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

// GROUP2
// ======
var group2 = panel1.add("group", undefined, {name: "group2"}); 
    group2.orientation = "row"; 
    group2.alignChildren = ["left","center"]; 
    group2.spacing = 10; 
    group2.margins = 0; 

// GROUP3
// ======
var group3 = group2.add("group", undefined, {name: "group3"}); 
    group3.preferredSize.width = 110; 
    group3.orientation = "row"; 
    group3.alignChildren = ["left","center"]; 
    group3.spacing = 10; 
    group3.margins = 0; 

var statictext2 = group3.add("statictext", undefined, undefined, {name: "statictext2"}); 
    statictext2.text = "X :"; 
    statictext2.preferredSize.width = 20; 

var edittext1 = group3.add('edittext {properties: {name: "edittext1"}}'); 
    edittext1.text = "0"; 
    edittext1.preferredSize.width = 60; 
    edittext1.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP4
// ======
var group4 = group2.add("group", undefined, {name: "group4"}); 
    group4.orientation = "row"; 
    group4.alignChildren = ["left","center"]; 
    group4.spacing = 10; 
    group4.margins = 0; 

var statictext3 = group4.add("statictext", undefined, undefined, {name: "statictext3"}); 
    statictext3.text = "W :"; 
    statictext3.preferredSize.width = 20; 

var edittext2 = group4.add('edittext {properties: {name: "edittext2"}}'); 
    edittext2.text = "0"; 
    edittext2.preferredSize.width = 60; 
    edittext2.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP5
// ======
var group5 = panel1.add("group", undefined, {name: "group5"}); 
    group5.orientation = "row"; 
    group5.alignChildren = ["left","center"]; 
    group5.spacing = 10; 
    group5.margins = 0; 

// GROUP6
// ======
var group6 = group5.add("group", undefined, {name: "group6"}); 
    group6.preferredSize.width = 110; 
    group6.orientation = "row"; 
    group6.alignChildren = ["left","center"]; 
    group6.spacing = 10; 
    group6.margins = 0; 

var statictext4 = group6.add("statictext", undefined, undefined, {name: "statictext4"}); 
    statictext4.text = "Y : "; 
    statictext4.preferredSize.width = 20; 

var edittext3 = group6.add('edittext {properties: {name: "edittext3"}}'); 
    edittext3.text = "0"; 
    edittext3.preferredSize.width = 60; 
    edittext3.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP7
// ======
var group7 = group5.add("group", undefined, {name: "group7"}); 
    group7.orientation = "row"; 
    group7.alignChildren = ["left","center"]; 
    group7.spacing = 10; 
    group7.margins = 0; 

var statictext5 = group7.add("statictext", undefined, undefined, {name: "statictext5"}); 
    statictext5.text = "H : "; 

var edittext4 = group7.add('edittext {properties: {name: "edittext4"}}'); 
    edittext4.text = "0"; 
    edittext4.preferredSize.width = 60; 
    edittext4.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// DIALOG
// ======
var divider1 = dialog.add("panel", undefined, undefined, {name: "divider1"}); 
    divider1.alignment = "fill"; 

// GROUP8
// ======
var group8 = dialog.add("group", undefined, {name: "group8"}); 
    group8.preferredSize.width = 270; 
    group8.orientation = "row"; 
    group8.alignChildren = ["left","center"]; 
    group8.spacing = 10; 
    group8.margins = 0; 

var checkbox1 = group8.add("checkbox", undefined, undefined, {name: "checkbox1"}); 
    checkbox1.text = "Change the object with values : "; 
    checkbox1.onClick = function (){
        group9.enabled = this.value;
        group12.enabled = this.value;
        button1.enabled = this.value;
        if(this.value){
            edittext5.text = edittext1.text;
            edittext6.text = edittext2.text;
            edittext7.text = edittext3.text;
            edittext8.text = edittext4.text;
            }
        else{
            edittext5.text = "";
            edittext6.text = "";
            edittext7.text = "";
            edittext8.text = "";
            }
        }

// PANEL2
// ======
var panel2 = dialog.add("panel", undefined, undefined, {name: "panel2"}); 
    panel2.text = "Change Object"; 
    panel2.preferredSize.width = 270; 
    panel2.preferredSize.height = 100; 
    panel2.orientation = "column"; 
    panel2.alignChildren = ["left","top"]; 
    panel2.spacing = 10; 
    panel2.margins = 10; 

// GROUP9
// ======
var group9 = panel2.add("group", undefined, {name: "group9"}); 
    group9.enabled = false; 
    group9.orientation = "row"; 
    group9.alignChildren = ["left","center"]; 
    group9.spacing = 10; 
    group9.margins = 0; 

// GROUP10
// =======
var group10 = group9.add("group", undefined, {name: "group10"}); 
    group10.preferredSize.width = 110; 
    group10.orientation = "row"; 
    group10.alignChildren = ["left","center"]; 
    group10.spacing = 10; 
    group10.margins = 0; 

var statictext6 = group10.add("statictext", undefined, undefined, {name: "statictext6"}); 
    statictext6.text = "X : "; 

var edittext5 = group10.add('edittext {properties: {name: "edittext5"}}'); 
    edittext5.preferredSize.width = 60; 
    edittext5.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP11
// =======
var group11 = group9.add("group", undefined, {name: "group11"}); 
    group11.orientation = "row"; 
    group11.alignChildren = ["left","center"]; 
    group11.spacing = 10; 
    group11.margins = 0; 

var statictext7 = group11.add("statictext", undefined, undefined, {name: "statictext7"}); 
    statictext7.text = "W : "; 

var edittext6 = group11.add('edittext {properties: {name: "edittext6"}}'); 
    edittext6.preferredSize.width = 60; 
    edittext6.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP12
// =======
var group12 = panel2.add("group", undefined, {name: "group12"}); 
    group12.enabled = false; 
    group12.orientation = "row"; 
    group12.alignChildren = ["left","center"]; 
    group12.spacing = 10; 
    group12.margins = 0; 

// GROUP13
// =======
var group13 = group12.add("group", undefined, {name: "group13"}); 
    group13.preferredSize.width = 110; 
    group13.orientation = "row"; 
    group13.alignChildren = ["left","center"]; 
    group13.spacing = 10; 
    group13.margins = 0; 

var statictext8 = group13.add("statictext", undefined, undefined, {name: "statictext8"}); 
    statictext8.text = "Y : "; 

var edittext7 = group13.add('edittext {properties: {name: "edittext7"}}'); 
    edittext7.preferredSize.width = 60; 
    edittext7.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP14
// =======
var group14 = group12.add("group", undefined, {name: "group14"}); 
    group14.orientation = "row"; 
    group14.alignChildren = ["left","center"]; 
    group14.spacing = 10; 
    group14.margins = 0; 

var statictext9 = group14.add("statictext", undefined, undefined, {name: "statictext9"}); 
    statictext9.text = "H : "; 

var edittext8 = group14.add('edittext {properties: {name: "edittext8"}}'); 
    edittext8.preferredSize.width = 60; 
    edittext8.addEventListener ("keyup", function (){
        if(this.text != ""){
            var tmpTxt = "";
            for(var c = 0; c < this.text.length; c++){
                if(parseInt(this.text[c]).toString().toLowerCase() != "nan" || this.text[c] == "."){
                    tmpTxt += this.text[c];
                    }
                }
            this.text = tmpTxt;
            }
        });

// GROUP15
// =======
var group15 = dialog.add("group", undefined, {name: "group15"}); 
    group15.preferredSize.width = 270; 
    group15.orientation = "row"; 
    group15.alignChildren = ["right","center"]; 
    group15.spacing = 10; 
    group15.margins = 0; 

var button1 = group15.add("button", undefined, undefined, {name: "button1"}); 
    button1.text = "Apply"; 
    button1.enabled = false;

var button2 = group15.add("button", undefined, undefined, {name: "button2"}); 
    button2.text = "Cancel"; 

if(dialog.show() == 1){
    $.bp();
    // Here you can put your execution code ///
    }

 

Best

Sunil

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
Reply
Loading...
Community Beginner ,
Feb 25, 2020

Copy link to clipboard

Copied

Sunil ...

If I understand all of the above correctly, it is an extensive amount of code to provide a very nice looking data entry window for 1 specific set of values to change to another set of values.

 

Basically, what I achieved with 14 lines of code that can take an infinite amount of data, you are suggesting that I replace with hundreds of lines of code that takes in 1 piece of data?

 

Since you have provided me excellent assitance in the past, I obviously am missing something here.  Outside of making things look very nice (as opposed to prompts), what exactly is this providing me?

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
Reply
Loading...
Adobe Community Professional ,
May 06, 2020

Copy link to clipboard

Copied

Hi any2cards,

I always try to help my fellow member with all my best effort.

And the reason why I put a little extra effort to make things look beautiful and permanent.

I believe that whatever you do, try to do it with perfection. There is a saying first impression is last impression.

So when you are giving your production floor some sort of functionality,  try to make it look good.

Try avoiding giving somebody temporary solution, give permanent solution, take a little extra time.

So that user should enjoy your UI. And if you put a little extra effort that will enhance your skills only.

 

In this UI user can fill all details and if they want any corrections as well they can do it after adding all those data.

Instead in prompt....... You know that right?

 

Best

Sunil

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
Reply
Loading...