Getting access to Adobe Illustrator’s app.activeDocument from ScriptUI dialog.

During the development of the next script for Illustrator, faced with a very interesting behavior. In my case, one of the active palette called a helper dialog boxes that have just had to initiate work with the active document, based on the input of these data. Then I noticed that the dialog boxes can’t receive / send data to the active document. During the search such problems and their solutions, I realized that should to think in the direction of BridgeTalk, declaring the target application. Scripts called in this way worked well, but were nuances. Firstly the script should be placed in quotes, with all its consequences, and variables are declared after the call, don’t read Solution turned out to be pretty simple, but not obvious — instead of calling individual commands through BridgeTalk, one only has to call the dialog window. That allows him and all functions called from, refer to the document, not breaking the usual style of coding.

For clarity, “two-button” version of the script that demonstrates the problem. Can try to make a call not through btExecute, and you will see that it will not work.

Originally published at on August 28, 2014.