Copy link to clipboard
Copied
I currently duplicate the contents of one document into another like so:
// add selected to document
if( docSelected.length > 0 ) {
// move items to selected document
// var newDoc = aDoc.documents.add();
if( docSelected.length > 0 ) {
for ( i = 0; i < docSelected.length; i++ ) {
docSelected[i].selected = false;
newItem = docSelected[i].duplicate( aDoc, ElementPlacement.PLACEATEND );
}
}
else {
docSelected.selected = false;
newItem = docSelected.parent.duplicate( aDoc,
ElementPlacement.PLACEATEND );
}
}
aDoc is the file where the content goes into.
All works.
After I place it or before (doesn't matter) I'd like to palce it at a specific area of the board. In example
top = 0, left = 0.
My attempt:
var activeLayer = aDoc.artLayers.getByName("Layer 1");
activeLayer.top = 0;
activeLayer.left = 0;
Didn't work. Any ideas how I could accomplish this?
the Layer object doesn't have "left" or "top" properties. You need to target the artboard directly to get the coordinates. Consider this very simple example:
#target Illustrator
//Description:
function test()
{
var doc = app.activeDocument;
var item = doc.pageItems[0];
var ab = app.activeDocument.artboards[0];
var rect = ab.artboardRect;
item.left = rect[0]; // Artboard.artboardRect[0] refers to the left edge of the artboard
item.top = rect[1]; // Artboard.artboardRect[0] refers to the l
...
Copy link to clipboard
Copied
the Layer object doesn't have "left" or "top" properties. You need to target the artboard directly to get the coordinates. Consider this very simple example:
#target Illustrator
//Description:
function test()
{
var doc = app.activeDocument;
var item = doc.pageItems[0];
var ab = app.activeDocument.artboards[0];
var rect = ab.artboardRect;
item.left = rect[0]; // Artboard.artboardRect[0] refers to the left edge of the artboard
item.top = rect[1]; // Artboard.artboardRect[0] refers to the left edge of the artboard
}
test();
Copy link to clipboard
Copied
Thank you so much. If there's multiple pageItems is there away to group them all at once and then apply the left top or would I have to loop over each one? @williamadowling
Copy link to clipboard
Copied
when you have all your items selected, you can use this:
app.executeMenuCommand("group");
//do the transformation/alignment stuff
app.executeMenuCommand("ungroup");