how can I manipulate ScriptUI state in Illustrator based on document state instead of button click?

65 Views Asked by At

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

0

There are 0 best solutions below