Skip to main content
Inspiring
July 25, 2022
Question

Writing the behavior of the UI window to change the active document

  • July 25, 2022
  • 1 reply
  • 662 views

Hi everyone....

There are two checkboxes in the UI window. The first one is responsible for activating the document called "Source_l.ai", the second one is responsible for activating the document called "Dest_l.ai". In addition, when you change the active document, the active layer of the document should change. For this I write the following code
----------------------------------------------------------------------

ch_Sourse.onClick = function(){
ch_Dest.value = false;
app.documents.getByName("Source_l.ai").activate();
app.activeDocument.activeLayer = app.activeDocument.layers[0];
app.redraw();
}

ch_Dest.onClick = function(){
ch_Sourse.value = false;
app.documents.getByName("Dest_l.ai").activate();
app.activeDocument.activeLayer = app.activeDocument.layers[1];
app.redraw();

}
------------------------------------------------------------------------

But with this implementation, the active document does not change, and the active layer of this document does not change. Maybe someone faced such a problem? Thanks in advance.

 
This topic has been closed for replies.

1 reply

Charu Rajput
Community Expert
Community Expert
July 25, 2022

Hi,

I have tested your code outside the click function and it is working fine. Could you post your complete code. Is your window is palette or dialog? Did you try to use try-catch block?

Best regards
AnyONAuthor
Inspiring
July 25, 2022

#target Illustrator;
#targetengine main;

// PALETTE
// =======
var palette = new Window("palette");
palette.text = "Devide PathItems";
palette.orientation = "column";
palette.alignChildren = ["center","center"];
palette.spacing = 10;
palette.margins = 12;

// GIMAGEREDUCION
// ==============
var gImageReducion = palette.add("group", undefined, {name: "gImageReducion"});
gImageReducion.preferredSize.width = 210;
gImageReducion.orientation = "column";
gImageReducion.alignChildren = ["center","center"];
gImageReducion.spacing = 0;
gImageReducion.margins = 5;

// PNUMOBJECTS
// ===========
var pNumObjects = gImageReducion.add("panel", undefined, undefined, {name: "pNumObjects"});
pNumObjects.text = "Source";
pNumObjects.preferredSize.width = 200;
pNumObjects.orientation = "row";
pNumObjects.alignChildren = ["center","center"];
pNumObjects.spacing = 50;
pNumObjects.margins = 15;

var ch_Sourse = pNumObjects.add("checkbox", undefined, undefined, {name: "ch_Sourse"});
ch_Sourse.helpTip = "Source image redaction";
ch_Sourse.text = "S.";
ch_Sourse.value = true;

var SText_AmountSource = pNumObjects.add("statictext", undefined, undefined, {name: "SText_AmountSource"});
SText_AmountSource.helpTip = "Amount pathItems on Source image on choosen layer";
SText_AmountSource.text = "0";
SText_AmountSource.preferredSize.width = 15;
SText_AmountSource.justify = "center";

// PNUMOBJECTS1
// ============
var pNumObjects1 = gImageReducion.add("panel", undefined, undefined, {name: "pNumObjects1"});
pNumObjects1.text = "Destination";
pNumObjects1.preferredSize.width = 200;
pNumObjects1.orientation = "row";
pNumObjects1.alignChildren = ["center","center"];
pNumObjects1.spacing = 50;
pNumObjects1.margins = 15;

var ch_Dest = pNumObjects1.add("checkbox", undefined, undefined, {name: "ch_Dest"});
ch_Dest.helpTip = "Destination image redaction";
ch_Dest.text = "D.";

var SText_AmountDestination = pNumObjects1.add("statictext", undefined, undefined, {name: "SText_AmountDestination"});
SText_AmountDestination.helpTip = "Amount pathItems on Destination image on choosen layer";
SText_AmountDestination.text = "0";
SText_AmountDestination.preferredSize.width = 15;
SText_AmountDestination.justify = "center";

// PDIVIDE
// =======
var pDivide = gImageReducion.add("panel", undefined, undefined, {name: "pDivide"});
pDivide.text = "Devide";
pDivide.preferredSize.width = 200;
pDivide.orientation = "row";
pDivide.alignChildren = ["center","center"];
pDivide.spacing = 5;
pDivide.margins = 15;

var Text_NumberDivision = pDivide.add('edittext {properties: {name: "Text_NumberDivision"}}');
Text_NumberDivision.helpTip = "number of divisions";
Text_NumberDivision.text = "0";
// Text_NumberDivision.preferredSize.width = 30;
Text_NumberDivision.characters = 3;

var Check_Selection = pDivide.add("checkbox", undefined, undefined, {name: "Check_Selection"});
Check_Selection.helpTip = "Divide pathitems on selected image";
Check_Selection.text = "Sel";
Check_Selection.value = true;
Check_Selection.alignment = ["center","center"];

var Check_Auto = pDivide.add("checkbox", undefined, undefined, {name: "Check_Auto"});
Check_Auto.helpTip = "Based on the difference in the number of objects,\ndivides the Image with a smaller number,\nchoosing for the next division the object\nwith the maximum area";
Check_Auto.text = "Auto";
Check_Auto.value = false;
Check_Auto.alignment = ["center","center"];

var Buttot_Devide = pDivide.add("button", undefined, undefined, {name: "Buttot_Devide"});
Buttot_Devide.helpTip = "Execute divide pathitems";
Buttot_Devide.preferredSize.width = 40;
Buttot_Devide.text = "D";

// PANCHOR
// =======
var pAnchor = gImageReducion.add("panel", undefined, undefined, {name: "pAnchor"});
pAnchor.text = "Anchor";
pAnchor.preferredSize.width = 200;
pAnchor.orientation = "row";
pAnchor.alignChildren = ["center","center"];
pAnchor.spacing = 0;
pAnchor.margins = 15;
pAnchor.alignment = ["center","center"];

var Button_AnchorUpdate = pAnchor.add("button", undefined, undefined, {name: "Button_AnchorUpdate"});
Button_AnchorUpdate.helpTip = "Update PathItems position in Explorer \nabout ACHOR position.";
Button_AnchorUpdate.text = "Update";
Button_AnchorUpdate.preferredSize.width = 150;

palette.show();

app.documents.getByName("Dest_l.ai").activate();

var NumLayers = app.activeDocument.layers.length - 1;

app.activeDocument.activeLayer = app.activeDocument.layers[NumLayers];

ch_Sourse.onClick = function(){
ch_Sourse.value = true;
ch_Dest.value = false;
app.documents.getByName("Source_l.ai").activate();
app.activeDocument.activeLayer = app.activeDocument.layers[0];
app.redraw();
}

ch_Dest.onClick = function(){
ch_Sourse.value = false;
ch_Dest.value = true;
app.documents.getByName("Dest_l.ai").activate();
app.activeDocument.activeLayer = app.activeDocument.layers[1];
app.redraw();

}

Charu Rajput
Community Expert
Community Expert
July 25, 2022

Hi,

Since you are using the palette, therefore it is not working. If you use the dialog window like 

Best regards