AI palette windows doesn't execute script
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
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);
