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

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

Engaged ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

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.

 
TOPICS
Scripting

Views

214

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

#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();

}

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

Copy link to clipboard

Copied

Hi,

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

Best regards

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

Copy link to clipboard

Copied

When I changed the timeframe to --

var palette = new Window("dialog");

and tried to run this UI , then the following happened.

When you try to change the value of one of the chechboxes, the value of the second chechbox does not change. And I get true value for both chechbox. And the change of the active document and layer does not occur ...

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

Copy link to clipboard

Copied

I am using little modified version as compared to yours. May be you can try to run below.

#target Illustrator;
#targetengine main;

// PALETTE
// =======
var palette = new Window("dialog");
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;

ch_Sourse.onClick = function () {
    ch_Sourse.value = true;
    ch_Dest.value = false;
    setDocument('Source_l.ai',0);
}

ch_Dest.onClick = function () {
    ch_Sourse.value = false;
    ch_Dest.value = true;
    setDocument('Dest_l.ai', 1);
}

palette.show();

app.documents.getByName("Dest_l.ai").activate();
var NumLayers = app.activeDocument.layers.length - 1;
app.activeDocument.activeLayer = app.activeDocument.layers[NumLayers];

function setDocument(documentName, layerIndex){
    app.documents.getByName(documentName).activate();
    app.activeDocument.activeLayer = app.activeDocument.layers[layerIndex];
    app.redraw();
}
Best regards

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

Copy link to clipboard

Copied

Yes, this option works... Thank you...

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

Copy link to clipboard

Copied

I don't think this is a complete solution. For example, I changed the active layer in the "Dest_l.ai" document to app.activeDocument.layers[2], and when I switch to the 'Source_l.ai' document, I want to get the same app.activeDocument.layers[2]. With the version you sent, the functions ch_Sourse.onClick and ch_Dest.onClick are written in the body of the code, before the expression " palette.show();". And therefore, if I assign a variable, for the current active layer, in the active document, then I will not be able to get its value. Is it possible to somehow take into account this moment?

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

Copy link to clipboard

Copied

I am not sure I get your question, but I see few lines are missing in my version. I added those.

#target Illustrator;
#targetengine main;

// PALETTE
// =======
var palette = new Window("dialog");
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;

ch_Sourse.onClick = function () {
    ch_Sourse.value = true;
    ch_Dest.value = false;
    setDocument('Source_l.ai', 0);
}

ch_Dest.onClick = function () {
    ch_Sourse.value = false;
    ch_Dest.value = true;
    setDocument('Dest_l.ai', 1);
}

app.documents.getByName("Dest_l.ai").activate();
var NumLayers = app.activeDocument.layers.length - 1;
app.activeDocument.activeLayer = app.activeDocument.layers[NumLayers];

palette.show();

function setDocument(documentName, layerIndex) {
    app.documents.getByName(documentName).activate();
    app.activeDocument.activeLayer = app.activeDocument.layers[layerIndex];
    app.redraw();
}

Best regards

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

Copy link to clipboard

Copied

LATEST

The goal of the UI I'm designing is the following.
I'm working with layer 2 of the document Source_l.ai . And I want to get the number of pathItems in this layer. In this case, the value of 0 for the SText_AmountSource variable should change the assignment of the number of pathItems. Then I switch to the Dest_l.ai document using the checkbox. In doing so, I should also make layer 2 active, and get the number of pathItems for that layer and put that value into the SText_AmountDestination variable. Values for the number of pathItems should be reflected in the UI . Such a course of action should be prescribed for each layer of both documents.

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