Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


app.paste work around

Participant ,
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

80

Likes

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 Professional ,
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

Likes

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

Copy link to clipboard

Copied

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

Likes

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 Professional ,
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

Likes

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
Enthusiast ,
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é.

 

Likes

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