Copy link to clipboard
Copied
Hi,
I'm trying for the beginning of my planned script to just export a simple PDF to a destination with the Scripting UI. Here is my code:
var genFenster = new Window ("dialog", "PG beta");
// Knopf für das generieren vom PDF Dokument
var genKnopf = genFenster.add ("button", undefined, "Generieren");
genKnopf.onClick = function () {
app.activeDocument.exportFile(ExportFormat.pdfType, File("testDocument.pdf"), false);
}
genFenster.show ();
Tried to debug it inside ExtendScript but it just enters a loop where it cannot force InDesign to finish it. I've marked with the red color where ExtendScript gets stuck.
Please help me get this started.
Try something like this:
var genFenster = new Window ("dialog", "PG beta");
// Knopf für das generieren vom PDF Dokument
var genKnopf = genFenster.add ("button", undefined, "Generieren");
genKnopf.onClick = function () {
genFenster.close(100);
}
var result = genFenster.show();
if (result === 100){
app.activeDocument.exportFile(ExportFormat.pdfType, File("testDocument.pdf"), false);
}
The problem with your script is that a modal dialog is open, and when it's open, InDesign can't do anything.
The so
...Copy link to clipboard
Copied
Try something like this:
var genFenster = new Window ("dialog", "PG beta");
// Knopf für das generieren vom PDF Dokument
var genKnopf = genFenster.add ("button", undefined, "Generieren");
genKnopf.onClick = function () {
genFenster.close(100);
}
var result = genFenster.show();
if (result === 100){
app.activeDocument.exportFile(ExportFormat.pdfType, File("testDocument.pdf"), false);
}
The problem with your script is that a modal dialog is open, and when it's open, InDesign can't do anything.
The solution is to close the dialog, and then perform the required InDesign function.
the close() function of a window can take any number, and it is passed to the show() method, so that way you can check what button was pressed, close the window, and act accordingly.
Ariel
Copy link to clipboard
Copied
Thanks man, it works. I can develop it further now. Weird approach. It's important that I understand your code since I need to develop it to reopen the dialog after the export completes.
Copy link to clipboard
Copied
If you need to reopen the dialog, you may be better off doing things differently.
Instead of using a "dialog"-type window, use a "palette" type window.
Palette-type windows are modeless (like InDesign's Find/Change dialog), which lets the user do things in InDesign even while the dialog is open.
However, it gets a little fiddly with a palette, because as soon as it is opened, the script terminates, and then it is destroyed, so it disappears.
The solution to that is to create a custom script engine, which is much easier than it sounds. So, modifying the example as follows should do the trick:
#targetengine MyNewEngine
var genFenster = new Window ("palette", "PG beta");
// Knopf für das generieren vom PDF Dokument
var genKnopf = genFenster.add ("button", undefined, "Generieren");
genKnopf.onClick = function () {
app.activeDocument.exportFile(ExportFormat.pdfType, File("testDocument.pdf"), false);
}
genFenster.show();
(By the way, your original suggestion of reopening the window after closing it doesn't work. I seem to recall that once a window is closed, it can't just be reopened with myWindow.show() again...)
Edit: Sorry, I've corrected the script here now (the first version in this post was not demonstrating the use of a palette properly).
Copy link to clipboard
Copied
I've tried it with doScript but your solution is far better. This settles my first step towards my automation script. Thanks so much. Looks like I need to read more into the documentation. I was aware of pallete type just was to scared to implement it, because I was not sure if it would make problems in the future. Seems like it's totally fine.
Copy link to clipboard
Copied
Peter Kahrel makes it all seem so easy:
http://www.kahrel.plus.com/indesign/scriptui.html
Highly recommended!
Ariel
Copy link to clipboard
Copied
Hello, this script is in german. What do I change to have it in english ?
Copy link to clipboard
Copied
Hello, this script is in german. What do I change to have it in english ?
The code methods and objects are in english. The variables and comments are german but can be anything you choose that isn't already taken by JavaScript—genFenster could be replaced by myDialog, theDialog, d, etc., but can't be Dialog:
var myDialog = new Window ("dialog", "PG beta");
var myButtons = myDialog.add ("button", undefined, "Export");
myButtons.onClick = function () {
myDialog.close(100);
}
var result = myDialog.show();
if (result === 100){
//Exports the active document to the given file path
app.activeDocument.exportFile(ExportFormat.PDF_TYPE, File(Folder.desktop + "/testDocument.pdf"), false);
}
Copy link to clipboard
Copied
Hi Rob,
good that you added a valid File object!
Don't know what version of the script Mika Fletcher is referring to…
Your adapted version is not the one using the "palette" type of window Ariel is suggesting in answer #3.
FWIW: One could add a third argument with a valid PDF Export preset when using method exportFile(), but this would require also a string that would not be independent of the language version of InDesign if one wants to use one of InDesign's generic presets. Nevertheless, the code is working "as is", because it is using the last used PDF Export preset for output.
Regards,
Uwe