0

Trying to hide a button depending on current document name. If the document is open then the button is hidden else display button.

The current code is not displaying the button at all.

if(!app.documents.length){
    add_group_Ai();
}
else{
    var currentDocument = app.activeDocument.name;
    var str = aiProjectFile.fullName;
    var fileName = str.substr(str.lastIndexOf("/")+1,str.length);
    
    if(fileName == currentDocument){
        alert('document already open');
        remove_group_Ai();
    }     
}



function remove_group_Ai(){
    group_Ai.remove(this.parent);
    dialog.layout.layout(true);
}

function add_group_Ai(){
    // GROUP_AI
    // ========
    var group_Ai = panel_namePlate.add("group", undefined, {name: "group_Ai"}); 
    group_Ai.orientation = "column"; 
    group_Ai.alignChildren = ["fill","top"]; 
    group_Ai.spacing = 10; 
    group_Ai.margins = 5; 
    group_Ai.alignment = ["center","top"]; 

    var btn_AiProj = group_Ai.add("button", undefined, undefined, {name: "btn_AiProj"}); 
        btn_AiProj.text = "Open Illustrator Project"; 
        btn_AiProj.alignment = ["center","top"]; 

        btn_AiProj.onClick = function(){ 
            aiProjectFile = File.openDialog();
            if (aiProjectFile) {
                var str = aiProjectFile.fullName;
                var fileName = str.substr(str.lastIndexOf("/")+1,str.length);
                projPathText.text = fileName;
                app.open(aiProjectFile);
            }
        };
  • It looks like the button will only appear if you have no documents open at all. Is that the intended result or do you want it to appear for everything except the specified document? – Jake L Oct 20 '22 at 15:01
  • Thanks for responding, I haven't looked at this in quite some time. We ended up scrapping this. – Jeff Pate Feb 07 '23 at 23:53

0 Answers0