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

How to undo after .relink(link File) image.

Explorer ,
Jul 13, 2021 Jul 13, 2021

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?

TOPICS
Scripting

Views

238

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

correct answers 1 Correct answer

Community Expert , Jul 13, 2021 Jul 13, 2021

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

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 13, 2021 Jul 13, 2021

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?

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
Explorer ,
Jul 13, 2021 Jul 13, 2021

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.

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 13, 2021 Jul 13, 2021

Copy link to clipboard

Copied

ok let me see if i can replicate that issue and i'll get back to 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
Community Expert ,
Jul 13, 2021 Jul 13, 2021

Copy link to clipboard

Copied

LATEST

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

 

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