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

How to Enable Object Preview in Dialog Boxes for InDesign Scripts?

Explorer ,
Aug 04, 2024 Aug 04, 2024

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".

Captura de tela 2024-08-04 162329.png

 

<Title renamed by MOD>

TOPICS
Feature request , How to , Scripting

Views

127

Translate

Translate

Report

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
Community Expert ,
Aug 04, 2024 Aug 04, 2024

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

})();

 

Votes

Translate

Translate

Report

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 ,
Aug 05, 2024 Aug 05, 2024

Copy link to clipboard

Copied

Thanks. I'll take a look.

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 05, 2024 Aug 05, 2024

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.

 

 

 

 

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 05, 2024 Aug 05, 2024

Copy link to clipboard

Copied

@Peter Kahrel is the "preview" part of ScriptUI or is it via Indesign's own dialog?

Votes

Translate

Translate

Report

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 ,
Aug 05, 2024 Aug 05, 2024

Copy link to clipboard

Copied

LATEST

"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.

 

Votes

Translate

Translate

Report

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