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

CS4 - paste() produces: an illustrator error occurred: 2('')

Explorer ,
Jan 14, 2011 Jan 14, 2011

Copy link to clipboard

Copied

I am automating copy and paste between two open files in Illustrator.I'm not using CreateFromFile since that strips variable names and otherwise alters the imported pageitems and makes them useless.

For some systems users get an error when the past command is used in the script.

Not much to it, after selected groups on the first document are selected a copy statement is used, the active document is changed, and a paste statement is used. It normally works but only on some combinations of selections on some computers. Adding a redraw() after the target document is activated avoids the error on some computers but not all.

copy();
doc.activate();

redraw();

doc.activeLayer = layerOption;
paste();

An error occurs on the paste(); statement

an illustrator error occurred: 2('')

I've run directly from the ExtendScript toolkit editor and tried adding extra redraws() (to allow adobe to catch up to the scripting) all to no avail.

Any ideas on what I can try?

TOPICS
Scripting

Views

1.6K

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
Adobe
Explorer ,
Feb 09, 2011 Feb 09, 2011

Copy link to clipboard

Copied

Putting an "alert" statement after the copy stops the error. This happens on different pc's even windows 7 64 bit with better hardware. I also tried creating a separate scratch disk for Adobe which made no difference.

So, this avoids the error:

copy();
alert('Click OK to continue');
doc.activate();
doc.activeLayer = layerOption;
paste();

Is there a command that I can use in JavaScript with AI that will wait but won't stop all activity? I tried "redraw()" but that doesn't do the job.

This is extraordinarily annoying. There are lots of bugs in Adobe Illustrator CS4 with scripting that I've run into but Adobe never released a single patch to AI CS4. Not a one. If upgrading to CS5 was free that'd be one thing but with dozens of users upgrading will be a major expense.

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
Guide ,
Feb 09, 2011 Feb 09, 2011

Copy link to clipboard

Copied

I find on numerous occasions an alert() is better than a redraw() at refreshing… I have not had this error thou yet…

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 ,
Feb 09, 2011 Feb 09, 2011

Copy link to clipboard

Copied

I get the feeling that the scripted commands outpace the ability of AI to process them completely. I had originally thought redraw() would make the client wait to catch up but that doesn't seem to be the case.

Maybe if there was a DoEvents() or otherwise idling command available that could be put into a loop and not just freeze the app like an empty javascript loop would. I guess I could try putting redraw() in a loop but that would probably just generate more commands that would back up.

Another post here reported that setTimeout won't work with Adobe JavaScript but I guess I could try and see for myself. It might be easier to just run 2 scripts in a row. 😐

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
New Here ,
May 17, 2018 May 17, 2018

Copy link to clipboard

Copied

Now is 2018, i got same error. in similar situation. Any idea how to solve that?

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 Beginner ,
Aug 29, 2021 Aug 29, 2021

Copy link to clipboard

Copied

2021 and still having the same problem in Illustrator CC.

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 ,
Aug 29, 2021 Aug 29, 2021

Copy link to clipboard

Copied

can you show what you're trying to accomplish? there might be alternative ways of doing the same without using paste() if that's the root of the problem

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 Beginner ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

JohnnyWing_0-1630353974523.png

 

can you show what you're trying to accomplish? there might be alternative ways of doing the same without using paste() if that's the root of the problem


By @CarlosCanto


Hi Carlos. 

I am trying to copy specific artwork from one file to another. The below code is hit or miss depending on the PC running it and whether I'm in the VS Code debugger or running the script from Illustrator's Script menu. 

This is just a slice of a larger flow - Ultimately, I am taking a data input file and generating art for each of the items with it based on a separate model file that varies by item. As the script iterates through the items in the data file, it opens the appropriate model file, adjusts it, copies it, then pastes it into a collection file and closes the model file. It then moves to the next item, loads the model, and repeats. In the end, they end up in one file.

 

app.activeDocument.layers.getByName("Template").layers.getByName(thistextitemsTotalCount).layers.getByName(layoutCode).hasSelectedArtwork = true;
  app.executeMenuCommand("group");
  app.copy();
  // app.executeMenuCommand('copy'); //this and app.copy produce seemingly identical results.
  app.activeDocument = targetDocument;
  app.activeDocument.activeLayer = app.activeDocument.layers.getByName(targetMaterial);
  app.executeMenuCommand('paste'); //If I use app.paste() here, I get an Illustrator runtime error. This version is silent.
  modelDocument.close(SaveOptions.DONOTSAVECHANGES);

 

 

At the time I posted my complaint above, I'd resolved to going and writing a java app to manipulate the SVG file contents by hand. If any thoughts on how to make this work consistently, though, I'd love to revisit it.

 

Observations: Running with vs code debugger results in the debugger crashing or sometimes getting a RuntimeException to flow through to it. 

Running as a script from AI, it apparently encounters these runtime errors silently and I end up with some artwork pasted, some not. The results are not predictable from what I can tell. 

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 ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

I personally never use paste() (because it seems unreliable).

 

I always use duplicate(), which is also not perfect, it sometimes crashes when you target a specific destination. ie a group you have just created on the destination document. However I've found that duplicating all art from doc A to doc B first works all the time. Then you can reposition and and place in the right layer/group, etc without issues.

 

Hope that helps.

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 Beginner ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

quote

I personally never use paste() (because it seems unreliable).

 

I always use duplicate(), which is also not perfect, it sometimes crashes when you target a specific destination. ie a group you have just created on the destination document. However I've found that duplicating all art from doc A to doc B first works all the time. Then you can reposition and and place in the right layer/group, etc without issues.

 

Hope that helps.


By @CarlosCanto

 

Those are great points, Carlos. Thanks for sharing.

I was able to code my java artwork generator using batik in about 4 hours and notice that it takes a fraction of the time to process (less than one second for any number of items I can throw at it). While I lose a few tools from Illustrator, I feel that abandoning ExtendScript and it's paste issues is the best choice.

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
Guide ,
Aug 29, 2021 Aug 29, 2021

Copy link to clipboard

Copied

I've tried this on both CS4 and CS6 and I get no errors. 

 

var doc1 = app.documents[0];
doc1.layers[0].hasSelectedArtwork = true;
var doc2 = documents[1];
app.copy();
doc2.activate();
app.paste();

 

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
Contributor ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

LATEST

Did you ever resolve this? It happens to me in 2021.  Can't figure out a work around.

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