Rename group, added with app.executeMenuCommand("group" )

Contributor ,
Feb 06, 2022 Feb 06, 2022

Copy link to clipboard

Copied

Hi!

any ideas how the group, added with app.executeMenuCommand("group"),

can be renamed immediately after creation?

TOPICS
Scripting

Views

117

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Adobe Community Professional , Feb 06, 2022 Feb 06, 2022
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 = ...

Likes

Translate

Translate
Adobe Community Professional , Feb 06, 2022 Feb 06, 2022
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";

Likes

Translate

Translate
Adobe Community Professional ,
Feb 06, 2022 Feb 06, 2022

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;
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 06, 2022 Feb 06, 2022

Copy link to clipboard

Copied

Hi @m1b,

it is what i need, thank you!

Please tell me how to hide this group 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 06, 2022 Feb 06, 2022

Copy link to clipboard

Copied

To hide the group, just add this line after newGroup.name = 'My Best Group Ever':

newGroup.hidden = true;

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 06, 2022 Feb 06, 2022

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";

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 06, 2022 Feb 06, 2022

Copy link to clipboard

Copied

LATEST

So simple!
Thank you!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines