Compound Shape belongs to the PluginItem
type because it is created in Illustrator by the Pathfinder plug-in. The PluginItem’s position
attribute sets the position of the top left corner of the object, just like the similar attribute for other objects. An alternative method of setting the position is to use the left
and top
attributes. The translate(x, y)
method is also used to move objects along the X, Y axes. Consider an example of moving a Compound Shape.
Both changing object coordinates via attribute and moving via method worked as usual. An unobvious bug is detected when there is a group among the elements of a Compound Shape.
In a Compound Shape like this, all nested groups remain in place, only the individual elements of the shape are moved. To accurately move all nested objects without knowing if any are inside the group, you would have to use the cumbersome method described in the “Access to Compound Shape” post.
var prnt = getTopParent(selection[0]);
for (var i = 0; i < prnt.pageItems.length; i++) {
prnt.pageItems[i].translate(50, 0);
}
function getTopParent(item) {
if (item.parent.typename !== "PluginItem") {
return getTopParent(item.parent);
} else {
return item;
}
}