Answered
How to pass a set of graphics as a parameter directly into a function?
The following is correct, but my current selection may include textboxs, so I cannot directly input the graphics into toLayer (graphics)?
var d = app.activeDocument;
var graphics = getGraphics(d.selection);
var items = d.selection;
toLayer(items)Do I have to convert to the current selection?
But this won't work, how can I directly convert the graphics to the current selection?
var d = app.activeDocument;
var graphics = getGraphics(d.selection);
var items = d.selection;
toLayer(graphics)More code:
var d = app.activeDocument;
var graphics = getGraphics(d.selection);
var items = d.selection;
toLayer(graphics)
//var items = d.selection;
//toLayer(items)
function toLayer(sel) {
var myLayer = app.activeDocument.layers.add({ name: "AAA" });
try {
//var topLayer = d.layers.firstItem();
for (j = 0; j < sel.length; j++) {
sel[j].itemLayer = myLayer;
}
} catch (e) { };
}
//GetImg by m1b
function getGraphics(items) {
var graphics = [];
if ('Array' === items.constructor.name) {
for (var i = 0; i < items.length; i++)
graphics = graphics.concat(getGraphics(items[i]));
}
else if (
items.hasOwnProperty('allGraphics')
&& items.allGraphics.length > 0
)
graphics = graphics.concat(items.allGraphics);
else if (
items.hasOwnProperty('allPageItems')
&& items.allPageItems.length > 0
)
graphics = graphics.concat(getGraphics(items.allGraphics));
else if ('Image' === items.constructor.name) {
graphics.push(items);
}
return graphics;
};
