Copy link to clipboard
Copied
Is there any way for InDesign to show the preview of an object in a dialog box? I noticed that the pie chart script (Claquos) does just that, but I don't know how this mechanism works. Does anyone know?
Link site of Claquos
What if I want a script to insert a rectangle into my document, and through a dialog box, I can preview what I'm going to insert? I could enter color or stroke options and it would show me in the preview. I usually get errors where "my dialog window is active".
<Title renamed by MOD>
Copy link to clipboard
Copied
Hi @eusoujpg, there are some basic drawing functions available in ScriptUI dialogs. I'm not sure if that it how Claquos does it, but this is one approach, assuming that you can draw what you need with these basic methods. Here is an example showing some ScriptUIGraphics capabilities. Note that this snippet creates a ScriptUI Window with a "custom" element stored in "canvas" property.
- Mark
(function () {
var size = 300;
var w = new Window("dialog {text:'Canvas Test', canvas:Custom {preferredSize:[" + size + "," + size + "]}}"),
canvas = w.canvas,
bottomUI = w.add("group {orientation:'row', alignment:['right','top'], alignChildren:'right' }"),
buttons = bottomUI.add("group {orientation:'row', alignment:['right','top'], alignChildren:'right' }"),
cancelButton = buttons.add('button', undefined, 'Cancel', { name: 'cancel' }),
okButton = buttons.add('button', undefined, 'Draw', { name: 'ok' });
canvas.onDraw = function () {
var g = canvas.graphics;
var color = [Math.random(), Math.random(), Math.random()],
left = Math.floor(Math.random() * size / 2),
top = Math.floor(Math.random() * size / 2),
width = Math.floor(Math.random() * (size - left)),
height = Math.floor(Math.random() * (size - top));
g.newPath();
switch (Math.floor(Math.random() * 3)) {
case 0:
g.rectPath(left, top, width, height);
break;
case 1:
g.ellipsePath(left, top, width, height);
break;
case 2:
g.moveTo(left, top);
g.lineTo(width, height);
break;
}
g.fillPath(g.newBrush(g.BrushType.SOLID_COLOR, color, 1));
g.strokePath(g.newPen(g.BrushType.SOLID_COLOR, color, 1));
};
okButton.onClick = function () {
canvas.notify('onDraw');
};
w.center();
return w.show();
})();
Copy link to clipboard
Copied
Thanks. I'll take a look.
Copy link to clipboard
Copied
> I usually get errors where "my dialog window is active".
For the window type, use palette, not dialog.
As to preview, Claquos draws a graphic in the script's window. What you're after is a preview as InDesign does it, actually modifying text. You can have the script make any changes, but you'll have to be able to undo them as well.
Copy link to clipboard
Copied
@Peter Kahrel is the "preview" part of ScriptUI or is it via Indesign's own dialog?
Copy link to clipboard
Copied
"Preview" as of the checkbox in native dialogs is similar to the undo modes of scripting, but even more complex.
Unfortunately deep in the guts of InDesign there is an assumption that every dialog follows that pattern (thus is a candidate for a "Preview" checkbox), predating the idea of scripted undo modes by years, so InDesign also includes scripted dialogs of any kind into that restriction. Actually this even predates ExtendScript (added in version 3 or 4) including ScriptUI.
Furthermore there is a mechanism that out of all native scripting commands (the properties and methods of InDesign DOM) only those explicitly allowed in dialogs can get processed. There are very few of such commands.