Skip to main content
Known Participant
December 31, 2009
Answered

How to move and resize a whole layer with different objects and groups

  • December 31, 2009
  • 1 reply
  • 2544 views

Ok, I am a bit confused here.Things are not working like I thought they would and the documentation has confused me more.

currently in my code I have

var embedLeftSleeve = new File(folderPath+"/LeftSleeve.ai");

var leftSleevePlaced = doc.groupItems.createFromFile(embedLeftSleeve);
                        leftSleevePlaced.top = currentHeight;
                        leftSleevePlaced.left = 0;

I am importing an AI file and trying to put it into its own layer. I want it (the imported ai file) into into it's own layer. And I would like the layer to be setup the exact way it was in the original. But, after the import it seems to group non-grouped items, some of the objects are not showing the same way they did (like a shape with a gradient fill in it).

And finally, I want to scale all of the items in that layer as if I selected the layerer in illustrator and scaled it by hand (but scripting it to a set scale).

Can someone please help me. I am digging deep into the documentations and looking all over online to find what I want with little luck.

John

This topic has been closed for replies.
Correct answer Muppet_Mark-QAl63s

attached as a cs2 file.

I just realized that the gradient might have a spot color in it. That might be causing a bug. I need to fix that too.


Yup Im getting problems with an unknown shading type encountered. Take that blend out and all else appears fine.

1 reply

otherjohnAuthor
Known Participant
December 31, 2009

Update to my script, I have found the scale and move but its still messing up my layers.

if ( app.documents.length > 0 && embedLeftSleeve.exists ) {           
                        var leftSleevePlaced = doc.groupItems.createFromFile(embedLeftSleeve);
                        leftSleevePlaced.resize(calculateSleeveScaleWidth((_artboardCount[4]*72)),calculateSleeveScaleHeight((_artboardCount[3]*72)));
                        leftSleevePlaced.top = currentHeight;
                        leftSleevePlaced.left = 0;
        }

Muppet_Mark-QAl63s
Inspiring
December 31, 2009

Any chance of a sample of your art? I had a quick and my test art does NOT break up or look any different.

I've been trying to build myself a set of library functions so my methods may appear a little odd.

This was fine for me…

#target illustrator

var sleveArt = new File ('~/Desktop/Untitled-2.ai');

var artName = sleveArt.name;

var docRef = app.activeDocument;

with (docRef) {

pageOrigin = [0,0];

rulerOrigin = [0,0];

var docHeight = height;

myLayer = layers.add();

myLayer.name = artName;

myGroup = myLayer.groupItems.createFromFile(sleveArt);

myGroup.top = docHeight;

myGroup.left = 0;

resizeObject(myGroup, 140, 140, 100, 'BL');

selection = null;

}

function resizeObject(obj, sX, sY, clw, tr) {

if (verifyObject(obj)) {

var transAbt = getAnchor(tr);

obj.resize(sX, sY, true, true, true, true, clw, transAbt);

return true;

}

}

function verifyObject(obj) {

if (obj.typename == 'CompoundPathItem'||'GraphItem' || 'GroupItem' || 'PathItem' || 'PlacedItem' || 'PluginItem' || 'RasterItem' || 'SymbolItem' || 'TextFrame') return true;

else return false;

}

function getAnchor(x) {

var thisTrans;

switch(x) {

case 'B' : thisTrans = Transformation.BOTTOM; break;

case 'BL' : thisTrans = Transformation.BOTTOMLEFT; break;

case 'BR' : thisTrans = Transformation.BOTTOMRIGHT; break;

case 'C' : thisTrans = Transformation.CENTER; break;

case 'DO' : thisTrans = Transformation.DOCUMENTORIGIN; break;

case 'L' : thisTrans = Transformation.LEFT; break;

case 'R' : thisTrans = Transformation.RIGHT; break;

case 'T' : thisTrans = Transformation.TOP; break;

case 'TL' : thisTrans = Transformation.TOPLEFT; break;

case 'TR' : thisTrans = Transformation.TOPRIGHT; break;

}

return thisTrans;

}

otherjohnAuthor
Known Participant
December 31, 2009

Sure, attached is the one sleeve.

You will see that the white gradient titled "fadeout" does not place correctly.

John