Dialog not Showing to Select Object Style to UnAnchor All Object Linked

Engaged ,
Jul 26, 2020

Copy link to clipboard

Copied

Hi Pros..

I'm Trying to Show Dialog to the user so he can Select Disired Object Style linked to any text frame so after clicking ok it will UnAnchor all Text frames within the selected object style but the dialog not showing at all, What I'm Missing! ,, Thank you for any help or advice, here is the code :

 

//Unanchored all Anchored Objects at Once That Have Object Style Name
//26-7-2020
if(app.documents.length > 0){
    var allobjectStyles = [];
    getObjStyle("", app.documents[0]);
    function getObjStyle(name, object){
        for(var c = 0; c < object.objectStyles.length; c++){
            if(name != ""){
                allobjectStyles.push(["["+name+"]//"+object.objectStyles[c].name, object.objectStyles[c].id]);
                }
            else{
                allobjectStyles.push([object.objectStyles[c].name, object.objectStyles[c].id]);
                }
            }
        }
    // DIALOG
    // ======
    var dialog = new Window("dialog"); 
        dialog.text = "Unanchored all Anchored Frames with Object Style"; 
        dialog.orientation = "column"; 
        dialog.alignChildren = ["left","top"]; 
        dialog.spacing = 10; 
        dialog.margins = 16; 

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

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

    var statictext2 = group2.add("statictext", undefined, undefined, {name: "statictext2"}); 
        statictext2.text = "Select Object style : "; 

    var dropdown1_array = ["-Select-"]; 
    var dropdown1 = group2.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array}); 
    
        for(var c = 0; c < allobjectStyles.length; c++){
            dropdown1.add("item", allobjectStyles[c][0]);
            }
        dropdown1.selection = 0; 
        dropdown1.preferredSize.width = 120; 

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

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

    var button1 = group3.add("button", undefined, undefined, {name: "OK"}); 
        button1.text = "UnAcnhor Selected Object Style"; 

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

//--Execution
//Check if a Document is Open
if (app.documents.length == 0) {
	alert ("No document is open.", "Caution");
	exit();
}
}
//Working in the Current Active Document
var myDoc = app.activeDocument;  
// to use to process entire document  
var myItems = myDoc.allPageItems;  
//Creating Founded Objects Array
var foundObjects = Array();  
  for(var i = 0; i < myItems.length; i++){  
  if(myItems[i].parent instanceof Character){foundObjects.push(myItems[i]);}  
}  
//Check if Anchored Objects not Found
	if ( myItems.length == 0 )
	{
		alert("No Anchored items found in this document!.", "Stop" );
		exit();
	}
//UnAnchored Process Started at Array Created
if(foundObjects.length > 0){  
   for(var i = 0; i < foundObjects.length; i++){  
       if (foundObjects [i].appliedObjectStyle == dropdown1.selection.toString()); {  
    var AnchoredObject = foundObjects[i].anchoredObjectSettings.releaseAnchoredObject();
  }  
}
}

//Check if the Program is Done
if (AnchoredObject < 0) {
	alert ("all Objects with Selected Style are Done.", "Stop");
	exit();
}

 

Best Regards

Mohammad

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

So the issue is that you were calling show method twice, like below

 

dialog.show()

//Test Cancel
//NEW Examination of User Choice.
if(dialog.show() == 2){   
 alert("Canceled by User!");
 exit(0);
}

 

So what was happening is the dialog was shown, on cancel nothing happens no alert is displayed, then the if is executed and a new dialog is executed. This is a very tiny dialog which cancels on pressing esc key, then the condition of if is fulfilled and the alert is shown.

What you need to do instead is call the show method just once like below

 

var a = dialog.show()

//Test Cancel
//NEW Examination of User Choice.
if(a == 2){   
  alert("Canceled by User!");
  exit(0);
}

 

Try this and let us know if this work now or not

 

-Manan

 

TOPICS
How to, Scripting

Views

98

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

Dialog not Showing to Select Object Style to UnAnchor All Object Linked

Engaged ,
Jul 26, 2020

Copy link to clipboard

Copied

Hi Pros..

I'm Trying to Show Dialog to the user so he can Select Disired Object Style linked to any text frame so after clicking ok it will UnAnchor all Text frames within the selected object style but the dialog not showing at all, What I'm Missing! ,, Thank you for any help or advice, here is the code :

 

//Unanchored all Anchored Objects at Once That Have Object Style Name
//26-7-2020
if(app.documents.length > 0){
    var allobjectStyles = [];
    getObjStyle("", app.documents[0]);
    function getObjStyle(name, object){
        for(var c = 0; c < object.objectStyles.length; c++){
            if(name != ""){
                allobjectStyles.push(["["+name+"]//"+object.objectStyles[c].name, object.objectStyles[c].id]);
                }
            else{
                allobjectStyles.push([object.objectStyles[c].name, object.objectStyles[c].id]);
                }
            }
        }
    // DIALOG
    // ======
    var dialog = new Window("dialog"); 
        dialog.text = "Unanchored all Anchored Frames with Object Style"; 
        dialog.orientation = "column"; 
        dialog.alignChildren = ["left","top"]; 
        dialog.spacing = 10; 
        dialog.margins = 16; 

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

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

    var statictext2 = group2.add("statictext", undefined, undefined, {name: "statictext2"}); 
        statictext2.text = "Select Object style : "; 

    var dropdown1_array = ["-Select-"]; 
    var dropdown1 = group2.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array}); 
    
        for(var c = 0; c < allobjectStyles.length; c++){
            dropdown1.add("item", allobjectStyles[c][0]);
            }
        dropdown1.selection = 0; 
        dropdown1.preferredSize.width = 120; 

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

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

    var button1 = group3.add("button", undefined, undefined, {name: "OK"}); 
        button1.text = "UnAcnhor Selected Object Style"; 

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

//--Execution
//Check if a Document is Open
if (app.documents.length == 0) {
	alert ("No document is open.", "Caution");
	exit();
}
}
//Working in the Current Active Document
var myDoc = app.activeDocument;  
// to use to process entire document  
var myItems = myDoc.allPageItems;  
//Creating Founded Objects Array
var foundObjects = Array();  
  for(var i = 0; i < myItems.length; i++){  
  if(myItems[i].parent instanceof Character){foundObjects.push(myItems[i]);}  
}  
//Check if Anchored Objects not Found
	if ( myItems.length == 0 )
	{
		alert("No Anchored items found in this document!.", "Stop" );
		exit();
	}
//UnAnchored Process Started at Array Created
if(foundObjects.length > 0){  
   for(var i = 0; i < foundObjects.length; i++){  
       if (foundObjects [i].appliedObjectStyle == dropdown1.selection.toString()); {  
    var AnchoredObject = foundObjects[i].anchoredObjectSettings.releaseAnchoredObject();
  }  
}
}

//Check if the Program is Done
if (AnchoredObject < 0) {
	alert ("all Objects with Selected Style are Done.", "Stop");
	exit();
}

 

Best Regards

Mohammad

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

So the issue is that you were calling show method twice, like below

 

dialog.show()

//Test Cancel
//NEW Examination of User Choice.
if(dialog.show() == 2){   
 alert("Canceled by User!");
 exit(0);
}

 

So what was happening is the dialog was shown, on cancel nothing happens no alert is displayed, then the if is executed and a new dialog is executed. This is a very tiny dialog which cancels on pressing esc key, then the condition of if is fulfilled and the alert is shown.

What you need to do instead is call the show method just once like below

 

var a = dialog.show()

//Test Cancel
//NEW Examination of User Choice.
if(a == 2){   
  alert("Canceled by User!");
  exit(0);
}

 

Try this and let us know if this work now or not

 

-Manan

 

TOPICS
How to, Scripting

Views

99

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

Copy link to clipboard

Copied

Hi Mohammad, at first look i see the show method call missing in your code. This method shows the dialog. Something like the following should be added

dialog.show()

-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
Reply
Loading...
Jul 26, 2020 1
Engaged ,
Jul 26, 2020

Copy link to clipboard

Copied

Thank you very much, i Forget to add that, everything is working

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...
Jul 26, 2020 0
Engaged ,
Jul 26, 2020

Copy link to clipboard

Copied

I tried to add cancel to the dialog but not working? What is the Problem? the script is continue to execute ?

if(dialog.show() == 2){   
          alert("Canceled by User!");
          exit(0);
}

 

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...
Jul 26, 2020 0
Engaged ,
Jul 26, 2020

Copy link to clipboard

Copied

i also tried to - but still cancel not working :

if(dialog.show() == 1){   
    if(edittext3.text == dropdown1.selection){
                 }
}   
      else {
          alert("Canceled by User!");
          exit(0);
}

 

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...
Jul 26, 2020 0
Adobe Community Professional ,
Jul 26, 2020

Copy link to clipboard

Copied

Should work, can you post the whole code snippet that you are now using. I tried a quick test and i see the alert being prompted when i click on the cancel button using the statement

if(dialog.show() == 2)
{
  alert("cancelled")
}

 

Don't you see the alert, one issue that i see is that you have not put any code in the ok button click handler so even if one cancels the dialog the code under the cancel if would still be executed. What you could do instead as a quick fix is try the following

if(dialog.show() == 2)
{
   alert("cancelled")
   exit()
}

 

-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
Reply
Loading...
Jul 26, 2020 0
Engaged ,
Jul 26, 2020

Copy link to clipboard

Copied

Here is the Complete Code But Cancel Not Working  :

//Unanchored all Anchored Objects at Once That Have Object Style Name
//26-7-2020
if(app.documents.length > 0){
    var allobjectStyles = [];
    getObjStyle("", app.documents[0]);
    function getObjStyle(name, object){
        for(var c = 0; c < object.objectStyles.length; c++){
            if(name != ""){
                allobjectStyles.push(["["+name+"]//"+object.objectStyles[c].name, object.objectStyles[c].id]);
                }
            else{
                allobjectStyles.push([object.objectStyles[c].name, object.objectStyles[c].id]);
                }
            }
        }
    // DIALOG
    // ======
    var dialog = new Window("dialog"); 
        dialog.text = "Unanchored all Anchored Frames with Object Style"; 
        dialog.orientation = "column"; 
        dialog.alignChildren = ["left","top"]; 
        dialog.spacing = 10; 
        dialog.margins = 16; 

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

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

    var statictext2 = group2.add("statictext", undefined, undefined, {name: "statictext2"}); 
        statictext2.text = "Select Object style : "; 

    var dropdown1_array = ["-Select-"]; 
    var dropdown1 = group2.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array}); 
    
        for(var c = 0; c < allobjectStyles.length; c++){
            dropdown1.add("item", allobjectStyles[c][0]);
            }
        dropdown1.selection = 0; 
        dropdown1.preferredSize.width = 120; 

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

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

    var button1 = group3.add("button", undefined, undefined, {name: "OK"}); 
        button1.text = "UnAnchor Selected Object Style"; 

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

//Showing the Dialog
dialog.show()

//Test Cancel
//NEW Examination of User Choice.
if(dialog.show() == 2){   
          alert("Canceled by User!");
          exit(0);
}
//End Cancel Test --  
//-------------------------

//--Execution
//Check if a Document is Open
if (app.documents.length == 0) {
	alert ("No document is open.", "Caution");
	exit();
}
}
//Working in the Current Active Document
var myDoc = app.activeDocument;  
// to use to process entire document  
var myItems = myDoc.allPageItems;  
//Creating Founded Objects Array
var foundObjects = Array();  
  for(var i = 0; i < myItems.length; i++){  
  if(myItems[i].parent instanceof Character){foundObjects.push(myItems[i]);}  
}  
//Check if Anchored Objects not Found
	if ( myItems.length == 0 )
	{
		alert("No Anchored items found in this document!.", "Stop" );
		exit();
	}
//UnAnchored Process Started at Array Created
if(foundObjects.length > 0){  
   for(var i = 0; i < foundObjects.length; i++){  
       if (foundObjects [i].appliedObjectStyle == dropdown1.selection.toString()); {  
    var AnchoredObject = foundObjects[i].anchoredObjectSettings.releaseAnchoredObject();
  }  
}
}

//Check if the Program is Done
if (AnchoredObject < 0) {
	alert ("all Objects with Selected Style are Done.", "Stop");
	exit();
}

 

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...
Jul 26, 2020 0
Adobe Community Professional ,
Jul 26, 2020

Copy link to clipboard

Copied

So the issue is that you were calling show method twice, like below

 

dialog.show()

//Test Cancel
//NEW Examination of User Choice.
if(dialog.show() == 2){   
 alert("Canceled by User!");
 exit(0);
}

 

So what was happening is the dialog was shown, on cancel nothing happens no alert is displayed, then the if is executed and a new dialog is executed. This is a very tiny dialog which cancels on pressing esc key, then the condition of if is fulfilled and the alert is shown.

What you need to do instead is call the show method just once like below

 

var a = dialog.show()

//Test Cancel
//NEW Examination of User Choice.
if(a == 2){   
  alert("Canceled by User!");
  exit(0);
}

 

Try this and let us know if this work now or not

 

-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
Reply
Loading...
Jul 26, 2020 2
medos20 LATEST
Engaged ,
Jul 27, 2020

Copy link to clipboard

Copied

Thank you very much, i learned a lot from you

 

Best Regards

Mohammad

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...
Jul 27, 2020 0