Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AI palette windows doesn't execute script

Explorer ,
Jan 26, 2023 Jan 26, 2023

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

 

 

TOPICS
Bug , Scripting
863
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 1 Correct answer

Community Expert , Jan 26, 2023 Jan 26, 2023
Translate
Adobe
Community Expert ,
Jan 26, 2023 Jan 26, 2023
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 26, 2023 Jan 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?

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
Guide ,
Jan 26, 2023 Jan 26, 2023

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

#targetengine "session";

 

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 26, 2023 Jan 26, 2023
LATEST

Doesn't run the script in my case 😞

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