[Branched] [JS] Duplicate, move a selected object by twice its width, colour the object and its "bg"
I have a Swatch that is a gradient named "BRONZE" that I would like to color the dup.selected object.
I've tried to add a line after dub.selected = true; but none of what I have tried has worked.
var doc = app.activeDocument;
var sel = doc.selection;
if (sel.length > 0) {
var pIt = sel[0];
var wdt = pIt.width;
var hdt = pIt.hieght;
var dub = pIt.duplicate();
doc.selection = null;
dub.translate(wdt*2, 0);
dub.selected = true;
generateBackground();
} else {
alert("No items are selected.");
}
function generateBackground() {
var sel = doc.selection;
var item = sel[0];
var bounds = item.geometricBounds;
var width = bounds[2] - bounds[0];
var height = bounds[1] - bounds[3];
var fillColor = new CMYKColor();
fillColor.cyan = 100;
fillColor.magenta = 100;
fillColor.yellow = 100;
fillColor.black = 100;
var background = doc.pathItems.rectangle(bounds[1], bounds[0], width, height)
background.fillColor = fillColor;
background.filled = true;
background.stroked = false;
background.zOrder(ZOrderMethod.SENDTOBACK);
}
[ branched from Moving a Selected Item twice it's width to Illustrator forum by moderator ]
[ title added by moderator ]
