Copy link to clipboard
Copied
Hi!
any ideas how the group, added with app.executeMenuCommand("group"),
can be renamed immediately after creation?
Hi @siomosp, since you are scripting, would you consider doing the scripting way? Here is a "group" function that groups items and returns the GroupItem so you can do further things with it, such as giving it a name.
- Mark
P.S. if you really need to use the app.executeMenuComment("group"), there is a way, but it isn't as neat.
/*
Group
Simple convenience function for Illustrator
by m1b
Example usage:
var grp = group(app.activeDocument.selection);
*/
var newGroup =
...
Although the question has already been answered by @m1b very well, I would like to briefly add the direct answer to the original question. One possible way would be:
app.executeMenuCommand("group");
app.activeDocument.selection[0].name = "My new group name";
Copy link to clipboard
Copied
Hi @siomosp, since you are scripting, would you consider doing the scripting way? Here is a "group" function that groups items and returns the GroupItem so you can do further things with it, such as giving it a name.
- Mark
P.S. if you really need to use the app.executeMenuComment("group"), there is a way, but it isn't as neat.
/*
Group
Simple convenience function for Illustrator
by m1b
Example usage:
var grp = group(app.activeDocument.selection);
*/
var newGroup = group(app.activeDocument.selection);
newGroup.name = 'My Best Group Ever';
function group(items, makeDuplicatesOfItems, whereToGroup) {
if (items == undefined || items.length == 0) {
return false;
}
var group = makeGroup();
if (whereToGroup == undefined) {
// behave like manual group
group.move(items[0], ElementPlacement.PLACEBEFORE);
} else {
// put the grouped items "into" the new location
group.move(whereToGroup, ElementPlacement.PLACEATBEGINNING);
}
for (var i = items.length - 1; i >= 0; i--) {
if (makeDuplicatesOfItems) {
items[i].duplicate(group, ElementPlacement.PLACEATBEGINNING);
} else {
items[i].move(group, ElementPlacement.PLACEATBEGINNING);
}
}
return group;
}
function makeGroup(name) {
var newGroup;
try {
newGroup = app.activeDocument.pageItems.getByName(name);
} catch (e) {
newGroup = app.activeDocument.activeLayer.groupItems.add();
if (name != undefined) newGroup.name = name;
}
return newGroup;
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
To hide the group, just add this line after newGroup.name = 'My Best Group Ever':
newGroup.hidden = true;
Copy link to clipboard
Copied
Although the question has already been answered by @m1b very well, I would like to briefly add the direct answer to the original question. One possible way would be:
app.executeMenuCommand("group");
app.activeDocument.selection[0].name = "My new group name";
Copy link to clipboard
Copied
So simple!
Thank you!