AdobeDocs / uxp-indesign

https://developer.adobe.com/indesign/uxp/
Apache License 2.0
21 stars 13 forks source link

Unable to get Enumerator correctly in UXP Scripting #24

Open CS5-Omachi opened 1 year ago

CS5-Omachi commented 1 year ago

I wrote the following code. This works with both UXPScript and ExtendScript.

var doc = app.documents.add();
doc.documentPreferences.pageOrientation = 2003395685; //PageOrientation.LANDSCAPE
if (doc.documentPreferences.pageOrientation === 2003395685 &&
    doc.documentPreferences.pageOrientation === PageOrientation.LANDSCAPE) {
    alert("OK");
} else if (doc.documentPreferences.pageOrientation == "LANDSCAPE") {
    alert("No!");
} else {
    alert("What?");
}
function alert(error) {
    var theDialog, theDialogCol;
    theDialog = app.dialogs.add();
    theDialog.canCancel = false;
    theDialogCol = theDialog.dialogColumns.add();
    theDialogCol.staticTexts.add({staticLabel: "" + error});
    theDialog.show();
    theDialog.destroy();
}

ExtendScript hits the first condition, but UXPScripting does not. So I created a second condition, which is rather inconvenient.

anoopvalomkot commented 1 year ago

@CS5-Omachi Comparison operators === and == doesn't work with ID objects in UXP scripting. This is documented at https://developer.adobe.com/indesign/uxp/guides/migrating-to-UXPScript/ Please instead use equals() method.

Below code should get it working if (doc.documentPreferences.pageOrientation.equals(PageOrientation.LANDSCAPE))