• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to rename layers with art board names?

Participant ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

Hey, I'm working on an icon project and I'd love it if the (1000) artboard names could be appended layer on each artboard. Anyone have a script or other options to consider?

TOPICS
Scripting , Tools

Views

1.7K

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 3 Correct answers

Community Expert , Jan 08, 2022 Jan 08, 2022

Here's a variation that might be better to test with. It takes a selection and names the items in the selection (whether they are grouped or not). - Mark'

 

 

/*

    Name Items Artboard Name

    by m1b: here https://community.adobe.com/t5/illustrator-discussions/script-to-rename-layers-with-art-board-names/m-p/12642361

    Names selected items after its artboard name.

*/

nameItemsArtboardName(app.activeDocument.selection);

function nameItemsArtboardName(items) {
    if (items == undefined || 
...

Votes

Translate

Translate
Explorer , Jan 11, 2022 Jan 11, 2022

Hi Anerson, I know your query has already been resolved by our colleague 'm1b', but I would like some feedback from you on my last attempt, if it's not too much trouble.
Thanks in advance.

/*
    Name-> OrganizeLayers
    By-> Inacio Felipe
    Where-> https://community.adobe.com/t5/illustrator-discussions/script-to-rename-layers-with-art-board-names/m-p/12643479#M305480
    what are you doing-> Bring subgroups to root and rename with string consisting of artboard name + group name + subgroup name
...

Votes

Translate

Translate
Explorer , Jan 13, 2022 Jan 13, 2022

Hi Anerson, yes it is a good idea to work with the layers, I will do that in the future. By the way, I applied your suggestions in the script, with the exception of the order of building the layers, as this is done following the order of the artboards, I hadn't thought otherwise.
I loved our conversation here. And I make myself available to others. Thank you!!

/*
    Name-> OrganizeLayers
    By-> Inacio Felipe
    Where-> https://community.adobe.com/t5/illustrator-discussions/script-to-rename-lay
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

Hi @John_Arneson, how would it work? Do the layers already exist? Do they have artwork already? Or do you simply want to generate a new layer for each artboard?

- Mark

Votes

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
Community Expert ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

Also, think carefully about whether you need layers *and* artboards. In my experience it is very rare to want both in concert. Perhaps you have a 2 dimensional matrix of icon versions—but that would mean you'd have 1000 versions of each icon. Anyway, just thinking about it. 🙂

- Mark

Votes

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
Participant ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

Thanks. Yeah there's 1000+ unique icons and there's various export reasons and workflows that make this setup ideal. Each icon is centered and grouped on its named artboards but has its generic name instead of something recognizable, which is a problem when we use Overlord Battke Axe to push the icons to After Effects. The name isn't recognizable so each instance gets name something not related to the source file and confusion ensures.  That makes sense? Maybe everything on the artboard takes on the respective name? Whether it becomes a new layer or not doesn't matter. Thanks for your thoughts. 

Votes

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
Advisor ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

Hello John,

 

I'm not sure if you want to rename the layers to match the artboard names or vice versa,  either way as long as the layers are organized in the same descending order as the artboards and the total # of each match you can use one of the two scripts below.

 

 

//Rename Layer names to match Artboards

    var doc = app.activeDocument;

    if (doc.artboards.length == doc.layers.length && doc.layers.length == doc.artboards.length) {

        for (var i = 0, l = doc.layers.length; i < l; i++) {

            var myLayer = doc.layers[i];

            myLayer.name = doc.artboards[i].name;

        }

        alert("Done!\nRenaming Layer names to match Artboards has completed.");

    } else {

        alert("Error!\n The number of Layers and Artboards do not match.");

    }

 

 

 

 

 

    //Rename Artboards to match Layer names

    var doc = app.activeDocument;

    if (doc.artboards.length == doc.layers.length && doc.layers.length == doc.artboards.length) {

        for (var i = 0, l = doc.artboards.length; i < l; i++) {

            var myArtBoards = doc.artboards[i];

            myArtBoards.name = doc.layers[i].name;

        }

        alert("Done!\nRenaming Artboards to match Layer names has completed.");

    } else {

        alert("Error!\n The number of Layers and Artboards do not match.");

    }

 

 

Regards,

Mike

Votes

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
Explorer ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

Hi John_Arneson,

I would like to help, but I need to understand your situation better. From what you can see so far, you'd like to export a large number of icons, placing them on individual, named layers so they can be easily identified after export. But what you have is a group of icons with a certain name, and each group of this one is centered in an artboard. Is that the situation?

In this scenario, we could solve it as follows:

1- in each artboard we undo the group of icons
2- we take each icon, check if it has a name, and then we rename it, either with the existing name, or we assign it a name formed by the name of its group and an index.
3- we create a layer with that same name and move the icon to it.

Does this algorithm serve you?

Best regards

Votes

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
Explorer ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

I started with Illustrator and JS a little while ago, but I believe the code is functional and hope it helps you.
So follow the code for this algorithm I mentioned above.

#target.Illustrator
#targetengine.organize()

organize()

function organize(){
    if (app.documents.length<1){
        alert('Open document for work')
        return
    }

    const doc=app.activeDocument
    const artbs=doc.artboards
    const lyr=doc.layers

    for(i=0;i<artbs.length;i++){
        try{
            // run through all artboards
            artbs.setActiveArtboardIndex(i)
            if(doc.selectObjectsOnActiveArtboard()==true){
                var select=doc.selection
                redraw()
            }else{
                return
            }

            // find groups, ungroup and through placing objects in the root layer
            // in this case 'group of icons'
            for(ii=0;ii<select.length;ii++){
                if (select[ii].typename=='GroupItem'){
                    groupName=select[ii].name
                    gp=select[ii]
                    for(id=0;id<gp.length;id++){
                        gp[id].move(lyr[0],ElementPlacement.PLACEATBEGINNING)
                        redraw()
                    }
                }else{
                    return
                }
            }

            // reselect all objects and rename if applicable
            // in this case 'icons'
            doc.selection=null
            doc.selectObjectsOnActiveArtboard()
            select=doc.selection
            var j=0
            var nameObj=''
            for(ii=0;ii<select.length;ii++){
                if (select[ii].name==''){
                    nameObj=groupName + '_' + j
                    select[ii].name=nameObj
                    j++
                }else{
                    nameObj=select[ii].name
                }

                // makes a new layer,if dont'exist, with name of object
                // in this case 'name of icon'
                var newLayer=''
                try {
                    newLayer = lyr.getByName(nameObj);
                } catch (e) {
                    // no layer by that name, so make it
                    newLayer = lyr.add()
                    newLayer.name = nameObj;
                    select[ii].move(newLayer,ElementPlacement.PLACEATBEGINNING)
                    redraw()
                }
            }

        }catch(e){alert('It is not possible to continue because:\n'+ e)}
    }
}

 

Best regards

Votes

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
Community Expert ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

Hi John, I'm not a fan of using layers for anything that doesn't *stack*, so I'd prefer to just name the groups you've made according to the artboard they are on. Here's my script. See what suits your situation best.

- Mark

 

 

/*

    Name First Group On Artboard

    by m1b: here https://community.adobe.com/t5/illustrator-discussions/script-to-rename-layers-with-art-board-names/m-p/12642361

    Finds the first group on each artboard and names it after that artboard.
    If there are two groups on the same artboard, only the first will be named.

*/

nameGroupsAfterArtboardName(app.activeDocument);

function nameGroupsAfterArtboardName(doc) {
    // all group items
    var items = doc.groupItems;
    // copy of artboards to array
    var allArtboards = [];
    for (var i = 0; i < doc.artboards.length; i++) {
        allArtboards[i] = doc.artboards[i];
    }
    // go over the items to check if they belong to an artboard
    for (var i = 0; i < items.length; i++) {
        var group = items[i];
        // we only want groups at the top level of the layer (not sub groups)
        if (group.parent.constructor.name == 'Layer') {
            // get a list of artboard indices (usually only one!)
            var abs = getArtboardsOfItem(allArtboards, group, true);
            if (abs.length > 0) {
                // name the group
                group.name = allArtboards[abs[0]].name;
                // we don't want to check this artboard again
                allArtboards.splice(abs[0], 1);
            }
        }
    }
}

function getArtboardsOfItem(abs, item, preferIndex) {
    // returns array of artboards that intersect with item
    // preferIndex param causes function to return index of each artboard
    abs = abs || app.activeDocument.artboards;
    var bounds = item.visibleBounds;
    var result = [];
    for (var i = 0; i < abs.length; i++) {
        if (boundsIntersectWithBounds(bounds, abs[i].artboardRect)) {
            if (preferIndex) {
                result.push(i);
            } else {
                result.push(abs[i]);
            }
        }
    }
    return result
}

function boundsIntersectWithBounds(bounds, containerBounds) {
    return !(
        containerBounds[0] > bounds[2] ||
        containerBounds[2] < bounds[0] ||
        containerBounds[1] < bounds[3] ||
        containerBounds[3] > bounds[1]
    );
}

 

 

Votes

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
Participant ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

Thanks guys, really appreciate your efforts this is way beyond my level! Here's some visuals of what the layers look like after using the script. It looks like they are ungrouping the existing <group> and renaming each piece of the icon sequentially. In Felipe's example the artboard name is appended to each piece, very cool. If those output layers could then be regrouped and named exactly as the artboard is that would be awesome - and that may be the intention but for some reason both scripts are crashing shortly after getting started...

 

...So I tested on a file w/ just one artboard and one layer and the script finished but unsucccessfully. Dddly Felipe your script didn't name the layers in this test as expected from the first 😞

 

Stepping back. It would be more accurate to say, and perhaps easier to script if we could rename each <group> after the artboard it's on. Bonus if the individual pieces had the same name and/or a sequential number but beyond what I think we 'need' - video people would probably love that though))

 

Hope this feedback helps and thanks again! 🙂 

 

Rename_Groups_Artboard_Name.png

 Test-2@8x.png

 

 

 

Votes

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
Community Expert ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

Haha, looks like we're not understanding your document structure. Can you post a link to an example ai document set up the way you want? Maybe you are using subLayers? Doesn't matter—an example will help us get there!

To get an idea of how I expect my script to work, do the following:

1. New document

2. Make a few artboards and name them

3. Paste a grouped icon on each artboard.

4. Run script

5. Expected result:each group will be named for the artboard it is on.

Let me know if that test works and we'll see what is different about your set up.

- Mark

 

P.S. My script ignores layers, except that it only names groups if they are direct children of layers (so it only names the top level groups).

Votes

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
Community Expert ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

Here's a variation that might be better to test with. It takes a selection and names the items in the selection (whether they are grouped or not). - Mark'

 

 

/*

    Name Items Artboard Name

    by m1b: here https://community.adobe.com/t5/illustrator-discussions/script-to-rename-layers-with-art-board-names/m-p/12642361

    Names selected items after its artboard name.

*/

nameItemsArtboardName(app.activeDocument.selection);

function nameItemsArtboardName(items) {
    if (items == undefined || items.length == 0) {
        alert('No items provided.');
        return;
    }
    var doc = items[0];
    while (doc.constructor.name != 'Document')
        doc = doc.parent;
    // copy of artboards to array
    var allArtboards = [];
    for (var i = 0; i < doc.artboards.length; i++) {
        allArtboards[i] = doc.artboards[i];
    }
    // go over the items to check if they belong to an artboard
    for (var i = 0; i < items.length; i++) {
        var item = items[i];
        // we only want groups at the top level of the layer (not sub groups)
        // if (item.parent.constructor.name == 'Layer') {
        // get a list of artboard indices (usually only one!)
        var abs = getArtboardsOfItem(allArtboards, item, true);
        if (abs.length > 0) {
            // name the group
            item.name = allArtboards[abs[0]].name;
            // uncomment next line to only name one item per artboard
            // allArtboards.splice(abs[0], 1);
        }
    }
    app.redraw();
}

function getArtboardsOfItem(abs, item, preferIndex) {
    // returns array of artboards that intersect with item
    // preferIndex param causes function to return index of each artboard
    abs = abs || app.activeDocument.artboards;
    var bounds = item.visibleBounds;
    var result = [];
    for (var i = 0; i < abs.length; i++) {
        if (boundsIntersectWithBounds(bounds, abs[i].artboardRect)) {
            if (preferIndex) {
                result.push(i);
            } else {
                result.push(abs[i]);
            }
        }
    }
    return result
}

function boundsIntersectWithBounds(bounds, containerBounds) {
    return !(
        containerBounds[0] > bounds[2] ||
        containerBounds[2] < bounds[0] ||
        containerBounds[1] < bounds[3] ||
        containerBounds[3] > bounds[1]
    );
}

 

 

Votes

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
Explorer ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

Hi guys !
dear John_Arneson, as 'm1b' said, it would be easier for us if you could provide an illustrator file with the structure of objects and layers. Without having this structure, the algorithm to be developed is very long and laborious, due to the fact that it is very generic. But I recoded the last script I sent you, restructuring the output of objects the way I imagine it should be for you. See if this one can help you:
ps.: It's a POC

/*
    Name-> OrganizeLayers
    By-> Inacio Felipe
    Where-> https://community.adobe.com/t5/illustrator-discussions/script-to-rename-layers-with-art-board-names/m-p/12643479#M305480
    what are you doing-> Bring subgroups to root and rename with string consisting of artboard name + group name + subgroup name
*/

#target.Illustrator
#targetengine.organize()

organize()

function organize(){
    if (app.documents.length<1){
        alert('Open document for work')
        return
    }

    const doc=app.activeDocument
    const artbs=doc.artboards
    const lyr=doc.layers

    for(i=0;i<artbs.length;i++){
        try{
            // run through all artboards
            artbs.setActiveArtboardIndex(i)
            if(doc.selectObjectsOnActiveArtboard()==true){
                var select=doc.selection
                redraw()
            }else{
                return
            }

            // find groups, ungroup and through placing objects in the root layer
            // in this case 'group of icons'
            for(ii=0;ii<select.length;ii++){
                if(select[ii].typename=='GroupItem'){
                    groupIcons=select[ii]
                    icons=groupIcons.groupItems
                    for(id=0;id<=icons.length;id++){
                        icon=icons[id]
                        // --- define the name of icon ----
                            if(artbs[i].name==''){
                                nameOfArtboard='Art_'+i
                            }else{
                                nameOfArtboard=artbs[i].name
                            }
                            if(groupIcons.name==''){
                                nameOfGroup='Grp_'+ii
                            }else{
                                nameOfGroup=groupIcons.name
                            }
                            if(icon.name==''){
                                nameOfIcon='Icon_'+id
                            }else{
                                nameOfIcon=icon.name
                            }
                            strName = nameOfArtboard + '_' + nameOfGroup + '_' + nameOfIcon
                        // --------------------------------

                        // make group on root with same name
                        var newgroup=''
                        try {
                            newgroup = doc.groupItems.getByName(strName);
                            icon.move(newgroup,ElementPlacement.PLACEATBEGINNING)
                        } catch (e) {
                            // no layer by that name, so make it
                            newgroup = doc.groupItems.add()
                            newgroup.name = strName
                            icon.move(newgroup,ElementPlacement.PLACEATBEGINNING)
                            redraw()
                        }
                        id=id-1
                        if(id>=1){break;}
                    }
                }
            }

        }catch(e){
            //alert('It is not possible to continue because:\n'+ e)
        }
    }
}
Best regards

Votes

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
Participant ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

Hey guys, sorry my reply from last night doesn't appear to have been sent 😕  The ungrouping steps seems to be problematic in that it's adjusting the layers inacurately, making elements disappear. Attaching a test file now w/ layers sequenced instead of nested inside the group as they were previously. (either way works for me but it would probably be more functional this way?)

Here's a test file link (save a copy please, copyrighted yada yada): https://assets.adobe.com/id/urn:aaid:sc:US:0cc60195-57a4-4181-a38f-ac12b92dbce0?view=difile and physical file attached. Feel like it got blocked last night... ?

 

Thanks in advance!

Votes

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
Participant ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

*Trying to attach file again...

Votes

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
Participant ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

**Didn't work x2, sorry. Hopefully the link works 🙂

Votes

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
Community Expert ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

Thanks John, that helps. My script seems to run fine except it doesn't update the UI so you won't see the changes until the layers panel updates next. I've edited my script above to include app.redraw() to fix this. Note that my script just names the selected items, not their layers. Perhaps I still don't understand what you want.

- Mark

Votes

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
Explorer ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

Hey John, I've ran a script i have and the result was the following, is this the final structure? The icon groups should be on the root?

Best regards

Votes

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
Participant ,
Jan 10, 2022 Jan 10, 2022

Copy link to clipboard

Copied

Hey @Inacio Felipe that looks like it's working! 🙂 I just see the one icon in upper left has expanded the circle shape. And the final format be whatever works best. I like the individual layers on the root, but could see it being useful to leave them inside layers as well (that's how I'll save the file later for ease of use)

@m1b

 

@m1b for some reason I'm not getting the results it sounds like you're seeing? It seems to rip through each layer but only creates new layers of the first artboard? 

Brian_screen Shot 2022-01-10 at 5.55.52 AM.png

Votes

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
Community Expert ,
Jan 10, 2022 Jan 10, 2022

Copy link to clipboard

Copied

Weird. This is what I did:

1. Opened your sample file.

2. Selected the items I wanted to rename.

3. Run my script that has:

nameItemsArtboardName(app.activeDocument.selection)

 

So when you do that it doesn't work? That's really strange. Sorry it's not working. I'll look into it when I get the chance. Note that my script doesn't do anything with layers—it just names selected items.

- Mark

 

Votes

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
Participant ,
Jan 10, 2022 Jan 10, 2022

Copy link to clipboard

Copied

AhhhHah! I wasn't selecting the objects to be named, sorry! It works fine in the test file. Working through some issues with the original doc now (knock on wood) THANK YOU.

Screen Shot 2022-01-10 at 2.53.55 PM.png

Votes

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
Participant ,
Jan 10, 2022 Jan 10, 2022

Copy link to clipboard

Copied

@Inacio Felipe Annd using the same 'select the objects' logic it looks like yours is working as well 🙂 But naming is happening down one layer for some reason. 

 

Screen Shot 2022-01-10 at 3.39.06 PM.png

Votes

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
Explorer ,
Jan 11, 2022 Jan 11, 2022

Copy link to clipboard

Copied

Ok Anerson, I'll look into this and then I'll talk to you. Thank you for that.

Best regards

Votes

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
Explorer ,
Jan 11, 2022 Jan 11, 2022

Copy link to clipboard

Copied

Hi Anerson, I know your query has already been resolved by our colleague 'm1b', but I would like some feedback from you on my last attempt, if it's not too much trouble.
Thanks in advance.

/*
    Name-> OrganizeLayers
    By-> Inacio Felipe
    Where-> https://community.adobe.com/t5/illustrator-discussions/script-to-rename-layers-with-art-board-names/m-p/12643479#M305480
    what are you doing-> Bring subgroups to root and rename with string consisting of artboard name + group name + subgroup name
*/

#target.Illustrator
#targetengine.organize()

function main(){
    // requerimentos
    try{
        if (app.documents.length<1){
            alert('Open document for work')
            return
        }
        else{
            //call the graphical interface
            UI()
        }
    }
    catch(erro){
        alert ("The script don't run because:\n" + erro)
    }
}
main();

function UI(){
    // Configuracao do Layout geral
        var janela=new Window('dialog','Organiza Layers',undefined,{closeButton: false})
        //var janela=new Window('palette','Organiza Camadas',undefined,{})
            //janela.preferedSize=[250,390]
            janela.alignChildren='fill'
        
        var painelInformacao=janela.add('panel',undefined,undefined)
            painelInformacao.alignChildren='fill'

            janela.add('staticText',undefined,'Options:')
        var panelRadios=janela.add('panel',undefined,undefined)
            panelRadios.orientation='column'
            panelRadios.alignChildren='fill'

        var panelButtons=janela.add('panel',undefined,undefined)
            panelButtons.alignChildren='center'
    //
    
    // Configuracao do Painel Informacao
        strInformacao='This script takes a name from the artboard and puts that name on the icon present on it, and also, allows the construction of a layer at the root for this icon.'
        var textoInformacao=painelInformacao.add('staticText',undefined,strInformacao,{multiline:true})
    //  

    // Configuracao do Painel Radio Origem
        var radioOnlyName=panelRadios.add('radioButton',undefined,'Only name')
            radioOnlyName.value=true
        var radioNameAndLayer=panelRadios.add('radioButton',undefined,'Layer and Name')
            radioNameAndLayer.value=false
    //

    // Configuracao do Painel Botoes
        var grupoBotoes=panelButtons.add('group')
            grupoBotoes.alignChildren='row'
            var bntOrganizar=grupoBotoes.add('button',undefined,'Organizar')
            var bntSair=grupoBotoes.add('button',undefined,'Sair')
    //

    // Configuracao Copyright
        var copyright = janela.add('statictext', undefined, '\u00A9 Inacio Felipe, inacioFelipens@gmail');
        copyright.justify = 'center';
        copyright.enabled = false;
    //

    // EVENTOS
        
        // Botoes
            bntOrganizar.onClick = function(){
                janela.close()
                organize(check=radioSelected(panelRadios))
            }
            
            bntSair.onClick = function(){
                janela.close()
            };
        //
    //
    
    janela.show()
}

function organize(check){
    var doc=app.activeDocument
    var artbs=doc.artboards
    var newLayer

    for(i=0; i<artbs.length; i++){
        var nameArtboard=artbs[i].name
        artbs.setActiveArtboardIndex(i)
        if(doc.selectObjectsOnActiveArtboard()==true){
            var select=doc.selection
            if (select.length>1){
                // if exist more one group
                for (ii=0; ii<select.length; ii++){
                    if (select[ii].typename=="GroupItem"){
                        nameObject=nameArtboard + '_'+ ii
                        select[ii].name=nameObject
                        if(check=='Layer and Name'){
                            newLayer=makeLayer(doc.layers,nameObject)
                            select[ii].move(newLayer,ElementPlacement.PLACEATBEGINNING)
                        }
                    }
                }
            }else{
                // if only group exists
                if (select[0].typename=="GroupItem"){
                     select[0].name=nameArtboard
                    if(check=='Layer and Name'){
                        newLayer=makeLayer(doc.layers,nameArtboard)
                        select[0].move(newLayer,ElementPlacement.PLACEATBEGINNING)
                    }
                }
            }
            redraw()
        }else{
            return
        }
    }
}

function makeLayer(level,strName){
    /* Essa funcao cria e retorna uma nova camada se ela nao existir no nivel indicado
        parametros:
        -> nivel:
            nivel onde sera criada a camada.
            Ex.: 'app.activeDocument.layers' para o primeiro nivel
        -> strNome:
            string com o nome que sera atribuido a nova layer
    */
    var newLayer
    try {
        newLayer = level.getByName(strName);
    } catch (e) {
        // no layer by that name, so make it
        newLayer = level.add()
        newLayer.name = strName;
    }
    return newLayer;
}

function radioSelected(controle){
    /*Essa funcao retorna o nome do controle radioButtom que foi selecionado
        Parametros:
        -> controle:
            o controle de ser um painel com radiobuttons
    */
    for (var i=0; i<controle.children.length; i++) {
      if(controle.children[i].value==true){
          controle=controle.children[i].text
          return controle
      }
    };
    //alert('Retonando o controle:\n' + controle ,'A funcao "radioSelecionado( )" diz:')
}
Best regards

Votes

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
Participant ,
Jan 11, 2022 Jan 11, 2022

Copy link to clipboard

Copied

Nice Inacio! Love it, dig the interface UX explaining what it does and give a couple options for ouput.

*I prefer not having to select the item I want to rename so I dig this. Can lock a layer to skip it anyway.

 

'Layer and Name' names the group and moves out of sub-layer.  It does leave an empty sub-layer group to delete which is super easy but maybe challenging to notice what's empty. The layers come out in reverse-order from high to low, maybe a way to start with the last artboard instead so they are in order from top down?

 

Screen Shot 2022-01-11 at 7.00.01 PM.png

 

'Only name' I prefer to have the top most layer name be to be changed instead of the sub-layer, not sure if that's intentional? Do like that if my layers were in order they'd remain in order.

Screen Shot 2022-01-11 at 7.00.51 PM.png

 

I noticed the UX interface calls out 'icon' and thought it could maybe be more generic. Here's some thoughts

 

"The script takes a  the name from the artboard and puts that name on the icon artwork (?) present on it, and also, OR?allows the construction of a layer at the root for this icon artwork (?)"

 

... or

 

Only Name: Takes the name from the artboard and appends to the artwork present on it in the current location

Layer & Name: Takes the name from the artboard and appends to the artwork present on it in a new layer

 

Buttons:

Organizar or Organize or DO IT! 

Sair(? didn't translate for me) or Exit or X

Votes

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
Explorer ,
Jan 12, 2022 Jan 12, 2022

Copy link to clipboard

Copied

Hi Anderson, first thanks for your suggestions. I will work on the translation and proposed logics. If you'll allow me, I'll be in touch again soon with these changes. Thank you once again for your attention and willingness to allow my learning.

Best regards

Votes

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