Copy link to clipboard
Copied
This is for FrameMaker, not InDesign, but it's basically a ScriptUI question.
It's also somewhat related to: https://community.adobe.com/t5/indesign-discussions/can-i-pass-arguments-to-include-script/td-p/1528...
Consider this simple code:
ShowWindow1();
ShowWindow2();
function ShowWindow1(){
var w = new Window ("palette", "Window 1");
btn1 = w.add ("button", undefined, "OK");
ckbx1 = w.add("checkbox", undefined,"Check Box");
w.add ("button", undefined, "Cancel");
btn1.onClick=function(){
alert("You clicked OK on Window 1");
}
w.show ();
}
function ShowWindow2(){
//w.close;
var w = new Window ("palette", "Window 2");
btn1 = w.add ("button", undefined, "OK");
w.add ("button", undefined, "Cancel");
btn1.onClick=function(){
alert("You clicked OK on Window 2");
alert(ckbx1.value);
}
w.show ();
}
I'm having a hard time understanding the following issues:
I actually have several scripts all using "win" as the name of the window and I want the scripts to close any open windows before opening the new one called out in the current script. I thought I would have an issue if the window had been closed previously, but it looks like I have an issue even closing the window if it is still open.
> I also want to avoid launching two identical windows if the script were run twice.
Check whether the window exists. If it doesn't, create it:
var w = Window.find ('palette', "Window 1");
if (!w) {
w = new Window ("palette", "Window 1");
...
...
}
w.show();
Similarly, to close an existing window, do this:
var w = Window.find ('palette', "Window 1");
if (w) {
w.close();
}
Issue 1 sounds as if it's still a problem with variable scope. Maybe check you variable (non-)declarations again.
> do I need to go through each of the scripts and make sure ALL the butttons and checkboxes use unique names?
That might be a good idea. But you can target specific controls by looking for them in specifuc windows. Use .find() to find a window, then use find() to find a named contro, in the window.
But another way of organising variables is to use a variable for a window, then
...Copy link to clipboard
Copied
Hi @Marshall_Brooks to elaborate on Peter's point, have a look at this code and see if my comments help you with the idea.
/* assign a new object to a variable `w1` */
var w1 = new Object();
/* variables in scope: 1
*
* w1 -> { }
*
*/
// add an empty object as w1's `pnl` property
// this is not a variable
w1.pnl = new Object();
/* variables in scope: 1
*
* w1 -> { pnl: {} }
*
*/
// add an empty object to w1's `pnl` property (an empty object)
// as `ckbx` property. not a variable.
w1.pnl.ckbx = new Object();
/* variables in scope: 1
*
* w1 -> { pnl: { ckbx: {} } }
*
*/
// define a variable that stores a reference to
// w1's pnl property's ckbx object
var window1_checkbox = w1.pnl.ckbx;
/* variables in scope: 2
*
* w1 -> { pnl: { ckbx: {} } }
* window1_checkbox -> {}
*
*/
// assign a value `true` to w1's pnl property's
// ckbx property's `value` property
window1_checkbox.value = true;
/* variables in scope: 2
*
* w1 -> { pnl: { ckbx: { value: true } } }
* window1_checkbox -> { value: true }
*
* Commentary: because `window1_checkbox` is a
* _reference_ to the same object as is stored
* in w1.pnl.ckbx, adding a new property `value`
* can be seen in both - because they point to
* the same object.
*/
// assign a new object to the variable `w2`
var w2 = new Object();
/* variables in scope: 3
*
* w1 -> { pnl: { ckbx: { value: true } } }
* window1_checkbox -> { value: true }
* w2 -> { }
*
*/
/* add a new object as a property of w2 `pnl` */
w2.pnl = new Object();
/* variables in scope: 3
*
* w1 -> { pnl: { ckbx: { value: true } } }
* window1_checkbox -> { value: true }
* w2 -> { pnl: {} }
*
* Commentary: we have created a property of
* `w2` called `pnl` but it doesn't conflict
* with w1's `pnl` because they are properties
* of different objects, and neither are
* variables; we still only have 3 variables.
*/
// assign an empty object to w2's pnl's ckbx
w2.pnl.ckbx = new Object();
/* variables in scope: 3
*
* w1 -> { pnl: { ckbx: { value: true } } }
* window1_checkbox -> { value: true }
* w2 -> { pnl: { ckbx: {} } }
*
*/
// assign w2's pnl's ckbx to a new variable
var window2_checkbox = w2.pnl.ckbx;
/* variables in scope: 4
*
* w1 -> { pnl: { ckbx: { value: true } } }
* window1_checkbox -> { value: true }
* w2 -> { pnl: { ckbx: {} } }
* window2_checkbox -> {}
*
*/
// assign `false` to w2's pbl's ckbx's `value` property
w2.pnl.ckbx.value = false;
/* variables in scope: 4
*
* w1 -> { pnl: { ckbx: { value: true } } }
* window1_checkbox -> { value: true }
* w2 -> { pnl: { ckbx: { value: false } } }
* window2_checkbox -> { value: false }
*
*/
// perform some assignments
window2_checkbox.value = window1_checkbox.value;
w1.pnl.ckbx.value = false;
/* variables in scope: 4
*
* w1 -> { pnl: { ckbx: { value: false } } }
* window1_checkbox -> { value: false }
* w2 -> { pnl: { ckbx: { value: true } } }
* window2_checkbox -> { value: true }
*
*/
Note: I use Object here because it is a javascript primitive type. You are talking about Windows and Panels and CheckBoxes but they are all descended from Object and the assignment of properties works the same way.
- Mark
Copy link to clipboard
Copied
@m1b - Super complicated and a LOT more involved than I thought, but that is helpful. I'm amazed it works as well as it does. (For example, I was using win in all my scritpts and the same checkbox names in many of them and it was really only the SelectAll and SingleSelect checkboxes that were giving me issues (but I ended up renaming almost everything just to be safe.)
Copy link to clipboard
Copied
Yes unfortunately it is super complicated. But you are working hard on it, and you can trust that the details will come to light as you keep playing.
Copy link to clipboard
Copied
I didn't want to start a new thread for this, but I ran into an issue. I combined most of my scripts into one large script. I made sure I have unique function names with no duplicate function names, unique variables, etc.
When I run my FrameMaker Script from the ESTK window, it seems to run fine.
When I run the script directly from FrameMaker, at several points it opens the ESTK window and shows a blank screen with Source1 on the tab, no message, or error message.
I'm assuming that means there is some error in the code, but I'm not sure the best way to determine what is causing the error so that I can eliminate it.
I tried setting a breakpoint and stepping through the code with F11 in ESTK and didn't see an error, but I didn't see an error running the script from ESTK normally, so I didn't expect to see an error from that.
How should I resolve this?
Copy link to clipboard
Copied
Disregard - Solved via Google's AI:
Find more inspiration, events, and resources on the new Adobe Community
Explore Now