Prompt for user input


#1

I know that the JXA scripts and some of the manually triggered object/stencil scripts can prompt for basic input beyond the message box demonstrated in the online automation docs, but what I’d really like the ability to do would be to prompt for key parameters that would drive behavior of some of the plugin’s actions directly from the plugin code itself.

Some of this I know I can get around via using listeners for events on properties, but I was wondering why there wasn’t any kind of direct interaction beyond the yes/no/cancel message box included in the API.

I’d really prefer not to have a bifurcated application that drives some behavior from externally and some from within the context of a given drawing simply because of limitations in the scripting API. It’s much harder to maintain and the UX is potentially dreadful depending on what kinds of things need to be done.

Can anyone shed some light on this?


#2

It seems that Omni added a “Form” Object to OmniJS, which allows user input. I hadn’t time to play with it yet, so I can’t say much about it.

Form

Form provides a mechanism to collect input from the user. Each form contains one or more instances of subclasses of Field , which are given a key. As the form is filled out, values object is populated with the values from the user interface.


#3

The rudiments are these:

(() => {
    'use strict';

    const dialogDisplay = [
            ['alpha', 'Alpha', 'ABC'],
            ['beta', 'Beta', 'DEF'],
            ['delta', 'Delta', 'GHI']
        ].reduce((frm, keyDisplayValue) => (
            frm.addField(
                new Form.Field.String(...keyDisplayValue)
            ),
            frm
        ), new Form())
        .show('Options:', 'OK');

    dialogDisplay.then(
        x => console.log(
            JSON.stringify(x.values)
        )
    );

    dialogDisplay.catch(
        e => console.log(
            'User cancelled',
            e.message
        )
    );
})();

Which on an OK click after:

Would yield the key-value dictionary:

{"alpha":"ABC","beta":"Changed default","delta":"GHI"}

and on a Cancel click would just yield:

User cancelled

There is some material on the ‘omni-automation’ site, for example at:


#4

Thanks guys. Not sure how I missed this, but that’s what I was looking for.

Thanks for the example, @draft8

Cheers,

ast