Copy link to clipboard
Copied
With script ui, by clicking the button.
I use bridge talk to run the script
I want to use the undo function in exception handling when an error occurs
I think that it is not working.
Does it not work within bridge talk?
I think whether to consider the whole processing at bridge talk as one operation
I tried undo in onclick after an error was returned
An error occurred without an app object.
Whichever method is impossible?
clCreateBtn.onClick = function(){
var bt = new BridgeTalk();
bt.target = "Illustrator";
bt.body = uneval(illustratorCreateLayer) + "(" + args+ ")";
bt.onResult = function(res) {
var result = eval(res.body);
if(result == "1"){
alert("error");
undo(); // app error no object!!!
return;
}
alert("ok");
}
bt.send();
}
function illustratorCreateLayer(){
var doc = activeDocument;
try{
// etc process
}catch(e){
undo(); // not working!!!
return "1";
}
return "0";
}
line at 11or25.
Please tell me if there is a solution.
Best regard.
Its hard way...
However, You can reference about CEP in below
And. you can read my Japanese article.
http://chuwa.iobb.net/tech/archive/2015/08/cep-extension-primer-1---setti.html
http://chuwa.iobb.net/tech/archive/2015/09/cep-extension-primer-2-build-u.html
Copy link to clipboard
Copied
undo method is under the application class. Try below.
app.undo();
Copy link to clipboard
Copied
Hi Ten A.
thank you for your answer.
However, reference from app does not work either.
Strictly speaking, it does not mean that an error occurs, it seems that nothing happens.
My prediction is that once the script finishes from the beginning to the end it is counted as one action on illlustarot,
Since it is assumed that from operation of path to catch until undo is one action
I think that nothing will happen because it is judged that there is nothing to undo yet.
Copy link to clipboard
Copied
I'm not shure what you want to do with that. However, If you think to do something with ScriptsUI's parette, I recommend to move it to CEP extension.
Copy link to clipboard
Copied
thank you for your answer.
I am using a script UI to create a script that automatically adds a fixed layer matching the selected list
However, a bug in the illustrator, "1346458189 ('PARM')" occasionally occurs.
Please see below for bugs.
Https://forums.adobe.com/thread/748031
So, if this unreasonable bug occurs, I would like to undo it here.
If this bug does not occur in the first place, it is a matter which I do not mind ...
I do not know, but what is CEP extension?
Best Regard.
Copy link to clipboard
Copied
Its hard way...
However, You can reference about CEP in below
And. you can read my Japanese article.
http://chuwa.iobb.net/tech/archive/2015/08/cep-extension-primer-1---setti.html
http://chuwa.iobb.net/tech/archive/2015/09/cep-extension-primer-2-build-u.html
Copy link to clipboard
Copied
It was a Japanese, I am also.
The Japanese forum is not very active, so I was asking questions on this forum.
While translating with google ...
Your article has been referred to when I was looking elsewhere.
I will refer to this article as well.
Thank you very much.
Copy link to clipboard
Copied
app.undo() does work. Your code works as well.
try this snippet, undo and redo buttons are dedicated BT functions. Test button is where your code is, I added accessing a layer that does not exist to generate an error, then it will call app.undo()
// test undo/redo, Carlos Canto
// https://forums.adobe.com/thread/2368801
#targetengine main
var win = new Window("palette","Test Undo/Redo");
var grpUndoRedo = win.add("group");
var btnUndo = grpUndoRedo.add("button", undefined, "U");
var btnRedo = grpUndoRedo.add("button", undefined, "R");
var grpBtns = win.add("group");
var btnCopy = grpBtns.add("button", undefined, "Test");
var btnPaste = grpBtns.add("button", undefined, "Paste");
btnCopy.size = btnPaste.size = [50,21];
btnUndo.size = btnRedo.size = [20,20];
btnUndo.onClick = function() {
var bt3 = new BridgeTalk;
bt3.target = "illustrator";
var msg3 = "\n" +
"app.undo();\n" +
"app.refresh();\n"
bt3.body = msg3;
bt3.send();
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
btnRedo.onClick = function() {
var bt4 = new BridgeTalk;
bt4.target = "illustrator";
var msg4 = "\n" +
"app.redo();\n" +
"app.refresh();\n"
bt4.body = msg4;
bt4.send();
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
btnCopy.onClick = function() {
args = 0;
//alert("Copy");
var bt5 = new BridgeTalk;
bt5.target = "illustrator";
bt5.body = uneval(illustratorCreateLayer) + "(" + args+ ")";
bt5.send();
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
btnPaste.onClick = function() {
alert("paste");
}
//----------------------------------------------------------------------------------------------------------------------------------------------
win.center();
win.show();
function illustratorCreateLayer(){
var doc = activeDocument;
try{
var ilayer = doc.layers['cut'];
}catch(e){
$.writeln(e);
app.undo();
return "1";
}
return "0";
}
Copy link to clipboard
Copied
CarlosCanto, Thank you for your reply.
I tried working on your script.
Certainly the undo, redo function itself is working properly.
Maybe my sample code or recognition is incorrect
For example, in the case of the following code.
try{
var lot = doc.layers['layer1'].textFrames[0]; /* Layer 1 is a prerequisite that exist */
var pos = [2, 5];
lot.position = pos;
var ilayer = doc.layers['cut'];
}catch(e){
$.writeln(e);
app.undo();
return "1";
}
After pos is set and the position is changed, it is caught at the location of the 'cut' layer
The value set with pos is not undoed.
In the click event, bridetalk "illustratorCreateLayer"
After that, depending on the return value
Do you mean to do bridgetalk with only "undo"?
Can I restore it unless I bridge talk twice?
best regard.
Copy link to clipboard
Copied
Hi taniwaki, add redraw() after re positioning your text
lot.position = pos;
app.redraw();
Copy link to clipboard
Copied
Hi Carlos Canto.
If you did "redraw" it was settled ...
I did not understand simple things.
For the time being, it seems to be possible to avoid an unknown error.
Thank you very much for your help.
I am grateful.
Copy link to clipboard
Copied
you're welcome, glad it worked.
You'll get the hang of it. BridgeTalk is the most complicated subject in my opinion. Well, xmp is complicated too as well