Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

Script to rename layers with art board names?

Participant ,
Jan 07, 2022 Jan 07, 2022

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
4.3K
Translate
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 || 
...
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
...
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
...
Translate
Adobe
Participant ,
Jan 12, 2022 Jan 12, 2022

Happy to reciprocate the tremendous favor and help make this as useful as possible.

Have you considered including an option to do the opposite and flip layer names to artboard names as well?

 

Translate
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 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-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','Organize Layers',undefined,{closeButton: false})
        //var janela=new Window('palette','Organize Layers',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='Only Name: Takes the name from the artboard and appends to the artwork present on it in the current location\n\nLayer & Name: Takes the name from the artboard and appends to the artwork present on it in a new layer'
        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,'Do It')
            var bntSair=grupoBotoes.add('button',undefined,'Exit')
    //

    // Configuracao Copyright
        var copyright = janela.add('statictext', undefined, '\u00A9 Inacio Felipe, inaciofelipens@gmail.com');
        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=artbs.length-1; i>=0; i--){
    //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
        }
    }
    delEmptyVazias(doc)
}

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 delEmptyVazias(level) {
    if (app.documents.length > 0) {
        var doc = level
        var layers = doc.layers;
        for (var i = layers.length - 1; i >= 0; i--) {
            if (layers[i].pageItems.length == 0) {
                layers[i].remove();
            }
        }
    } else {
        alert('Is necessary any document for continue')
    }
}

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
Translate
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 14, 2022 Jan 14, 2022
LATEST

Sweet, thanks dude. I really dig this final product! šŸ™‚ 

Translate
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