Skip to main content
Participating Frequently
January 26, 2023
Answered

AI palette windows doesn't execute script

  • January 26, 2023
  • 2 replies
  • 813 views

Hi guys, I am new to AI scripting and  I am trying to build an dockable palette simillar that we can have in AE
I creating new palette and runing my script code, once I run the code from VScode the palette is popping up, however the script stops exectuing at 

var initializeDoc = app.open(files[0], DocumentColorSpace.RGB);
try catch shows erorr "

Error: there is no document" 

If i change in new Window() 'palette' to 'dialog' everything runs normally. What can be the reason. Is palettes allowed in AI and if no, then is there a way to prevent freezing app until the panel isn't closed (this what happens with dialog panels)?

 

function buildUI(ob){
  var dialog = (ob instanceof Panel) ? ob : new Window("dialog", "Outliner", undefined, {closeButton: true});
    dialog.text = "Dialog"; 
    dialog.orientation = "column"; 
    dialog.alignChildren = ["center","top"]; 
    dialog.spacing = 10; 
    dialog.margins = 16; 

var button1 = dialog.add("button", undefined, undefined, {name: "button1"}); 
    button1.text = "Button"; 
    button1.onClick = function(){
      var sourceFolder = Folder.selectDialog( "Select the folder" );
      runMyScript(sourceFolder)
    }

    return dialog
}

var panel = buildUI(this)
panel.center();
panel.show();

function runMyScript(sourceFolder){
    if(sourceFolder == null) return

    var files = sourceFolder.getFiles("*.pdf");
    if(files.length == 0) {alert('Please select folder with PDF files'); return}

    //CODE STOPS HERE - Error: there is no document 
    var initializeDoc = app.open(files[0], DocumentColorSpace.RGB);

 

 

This topic has been closed for replies.

2 replies

femkeblanco
Legend
January 26, 2023

For me, a palette doesn't run unless the script starts with

#targetengine "session";

 

Participating Frequently
January 26, 2023

Doesn't run the script in my case 😞

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
January 26, 2023
Participating Frequently
January 26, 2023

Thank you, it seems to work for me! Btw is there a way to pass nested functions as a string for "script" for bridgeTalk?