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

app.paste work around

Contributor ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

According to this post almost 10 years ago there is an error when using app.paste() in ai.

an illustrator error occurred: 2('')

I'm experience this error in AI current release with the following code:

app.executeMenuCommand("group");
app.copy();
app.executeMenuCommand("ungroup");

var mainTemplateLayer = aDoc.layers.getByName("Placement" + plcIx);
var pLayerTop = mainTemplateLayer.pageItems[0].top;
var pLayerLeft = mainTemplateLayer.pageItems[0].left;
var pLayerWidth = mainTemplateLayer.pageItems[0].width;
var pLayerHeight = mainTemplateLayer.pageItems[0].height;

aDoc.activeLayer = mainTemplateLayer;

app.paste();

 

I've tried replacing app.paste() with 

app.executeMenuCommand("paste");

This seems to be also an issue because it doesn't paste into the correct layer. 

I know duplicate is an option but I'm hesitant to use it because some layers have alot of vector data so it'll be alot to looop over each item and duplicate.  

If I add an alert to the code paste doesn't error and also executeMenuCommand paste works and pastes into the appropriate layer.  Not sure why it does that but I suspect it switches layers before the paste is initiated.

 

Any ideas how I can work around this?

TOPICS
Scripting

Views

223

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

Copy link to clipboard

Copied

Hi,

I have tried this but did not face this error. 

Is this error occurs everytime or it is specific to the document?

Best regards

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 20, 2021 Nov 20, 2021

Copy link to clipboard

Copied

Everytime but on pc only.  On mac it doesn't happen.

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 ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

LATEST

Ohh I see. I am sorry, I am using mac, so can't test it on Windows.

Best regards

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
Advocate ,
Nov 18, 2021 Nov 18, 2021

Copy link to clipboard

Copied

Hi,

Fonctionne aussi pour moi, j'ajouterai que  group et ungroup sont inutiles.

aDoc = activeDocument;
//app.executeMenuCommand("group");
app.copy();
//app.executeMenuCommand("ungroup");
var plcIx = 1;
var mainTemplateLayer = aDoc.layers.getByName("Placement" + plcIx);
var pLayerTop = mainTemplateLayer.pageItems[0].top;
var pLayerLeft = mainTemplateLayer.pageItems[0].left;
var pLayerWidth = mainTemplateLayer.pageItems[0].width;
var pLayerHeight = mainTemplateLayer.pageItems[0].height;
aDoc.activeLayer = mainTemplateLayer;
app.paste();

Cordialement René.

 

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