0
votes

I'm having a little problem with an JS script in InDesign. I want to place an empty rectangle when clicking on a button. The creation outsite the onClick()-function works fine, but when I copy the exact code inside the onClick, it doesn't work.

main();
function main()
{
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

    //Window
    var dlg = new Window('dialog', "Window");     
    dlg.size = [250,150];

    //Add button to window
    var myButtonGroup = dlg.add ("group");
    myButtonGroup.orientation = "column";
    var search = myButtonGroup.add ("button", undefined, "Do!");

    // Totally works fine 
    var doc = app.activeDocument;
    var rect = doc.rectangles.add({geometricBounds : [0,0,32,100], fillColor : doc.swatches.item("None"), strokeColor : doc.swatches.item("None")});   


    //onClick event
     search.onClick = function() {
        alert("working");
       //Alert is working, code below not 
       var doc = app.activeDocument;
       var rect = doc.rectangles.add({geometricBounds : [0,0,32,100], fillColor : doc.swatches.item("None"), strokeColor : doc.swatches.item("None")});   
     }

    dlg.show();
}

I'm new to Indesign JS programming, so please be indulgent :) I am using InDesign CC 2020 and Javascript.

Best regards Alexander

1

1 Answers

1
votes

Ok, it worked when I add #targetengine "session" and create a 'palette' instead of 'window'.

Why? Don't ask me haha!

Best regards Alex