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?
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?
Copy link to clipboard
Copied
Everytime but on pc only. On mac it doesn't happen.
Copy link to clipboard
Copied
Ohh I see. I am sorry, I am using mac, so can't test it on Windows.
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é.