Copy link to clipboard
Copied
Can anyone help me please, I can't undo it after relinking the .relink(link File) image, sometimes I relink the wrong image and I just want to back to the original image but unfortunately, I can't undo it, In after effects so much easier to do with beginUndoGroup() and endUndoGroup() but I can find a solution to undo after relinking image. does anyone have any suggestions on how to solve this problem?
ok so the same thing happens to me, which is good becasue at least it's a consistent issue. I guess relinking just doesn't produce an undo state (which is usuallysomething i'm looking for becasue most undo states just end up complicating things IMO.
But i did come up with a solution, though whether it's clever or even feasible is up to you... Basically what i did was save the original linked file object as a variable. then, relink the image, then pop up a dialog asking if you want to revert th
...Copy link to clipboard
Copied
app.undo();
?
*edit*
are you saying that the relink happens somewhere in the middle of the script, so if you undo, it will not undo the relink, but rather something else that happened afterwords?
Copy link to clipboard
Copied
Sorry, probably I don't explain properly, when I execute a script to replace the active image file in illustrator .relink(link File), if I decided to go back to the original file Ctrl+Z some reason does not work.
Copy link to clipboard
Copied
ok let me see if i can replicate that issue and i'll get back to you.
Copy link to clipboard
Copied
ok so the same thing happens to me, which is good becasue at least it's a consistent issue. I guess relinking just doesn't produce an undo state (which is usuallysomething i'm looking for becasue most undo states just end up complicating things IMO.
But i did come up with a solution, though whether it's clever or even feasible is up to you... Basically what i did was save the original linked file object as a variable. then, relink the image, then pop up a dialog asking if you want to revert the change. As this is written, you'll have to make the decision to revert at runtime (like. after the script finishes, you can't go back and revert it. it's possible to save the file path to a local text file that could be read by some subsequent "revert" script.. But if you have multiple images, it might get a little confusing about which ones needs to be reverted and which ones don't).
**Edited to remove some arguments to the test function that weren't supposed to be there.
#target Illustrator
function test()
{
var doc = app.activeDocument;
var link = doc.placedItems[0];
var originalFile = link.file;
var newFile = File("path/to/new/file.ext");
link.relink(newFile);//this assumes that newFile does in fact exist
app.redraw(); //redraw the screen so that you can see the change before the dialog pops up
var w = new Window("dialog");
var msg = w.add("statictext",undefined,"Revert?");
var btnGroup = w.add("group");
var yes = btnGroup.add("button",undefined,"Yes");
var no = btnGroup.add("button",undefined,"No");
yes.onClick = function()
{
//revert the linked file
link.relink(originalFile);
w.close();
}
no.onClick = function()
{
//don't revert. just close the dialog and move on.
w.close();
}
w.show();
}
test();