Skip navigation
Dan Rodney 46 posts
Jan 18, 2010
Currently Being Moderated

[JS] ScriptUI and MeasurementEditboxes

May 18, 2012 8:58 AM

Tags: #javascript #indesign #scripting #extendscript #scriptui #editboxes

I've avoided using ScriptUI because of its lack of MeasurementEditboxes. But the time has come that I really want to use ScriptUI and I want to see if there is a workaround to some of the limitations of edittext boxes in ScriptUI. Before I list the issues, let me say that I'd love if we can all come up with a solution here that everyone can use. I think as a scripting comunity there will be lots of other people that can benefit from this solution. But at the same time I am willing to pay for a fix. Whether it's something a fellow scriptor has already developed or can develop, I need to solve this: for free or payment.

 

Onto the issues:

  1. Up/down arrows must increment values. Shift-arrows should increment larger values. This must work with inches, mm or picas. So 1p0 would be come 1p1, 1p11 would become 2p0. 1 in would become 1.125 in etc.
  2. If you type in a different form of measurements InDesign must translate into the current measurements. If the editbox is for inches, typing picas or mm should auto convert to inches, just like the native InDesign UI does.
  3. Math must work in editboxes. If you enter "1/8 in" InDesign should figure out "0.125 in". You should be able to enter "2.25 in + 0.125 in" and have InDesign do the math. CS6 now does complex math such as "1 in + 1/8 in" so that would be ideal. This math should also work with different measurement types such as "1 in + 1p".

 

I've seen solutions for issues 1 and 2 in this sidenotes script:

http://www.kahrel.plus.com/indesign/sidenotes.html

... but it doesn't like p6, only 0p6. People shouldn't have to type the 0. (But thanks Kahrel for this great example as well as you Script UI For Dummies. It's been helpful.)

 

I've not found any existing solutions to issues 3.

 

Those are the issues as I see them. Can we fix them?

 

Let me end by begging Adobe to please add MeasurementEditboxes into ScriptUI. Now that InDesign CS6 can do complex math in their editboxes, we need these native controls more than ever. I thought when ScriptUI was first added it would continue to advance and get controls such as this. Years later I guess I was wrong. Maybe it's just not a priority because it doesn't seem to sell upgrades? Please help us to create great scripting interfaces that feel native. They already exist in the other scripting dialogs, why not in ScriptUI? While you're at it, why not through in ones with up/down button tickers like InDesign has!

 

OK, rant over and let's get back to making this work.

 

Thanks in advance,

Dan

 
Replies
  • Currently Being Moderated
    May 18, 2012 11:57 AM   in reply to Dan Rodney

    While I'd never say never, the odds of your geting a native measurement combo box in ScriptUI are quite low.

     

    I wrote some fairly intense ScriptUI back in the CS4 timeframe to show how a measurement combo box (among other ID types) could be mimicked in ID.

     

    I don't think I handled all the cases (it was a while back, and I don't specifically recall) you mentioned. Meanwhile, it would be a great start for you to achieve what you want.

     

    Go to www.creativescripting.net, click the free stuff link. It's at the top

     

    Regards

     
    |
    Mark as:
  • Currently Being Moderated
    May 18, 2012 4:16 PM   in reply to Dan Rodney

    Hi Dan,

     

    I worked for two years on a (huge!) ExtendScript framework intented to simplify my InDesign scripts (from CS4). It wraps many features, including an advanced ScriptUI module. Basically I planned to use that framework for my own products, but now I'm seriously wondering whether it could be useful to 'third parties.' Although this doesn't answer all your requirements (in particular, your third point is not supported), my measurement edit controls meet some of the behaviors you're looking after.

     

    Here is a very simple dialog based on that framework:

    http://www.indiscripts.com/blog/public/ScriptUIMetricControls.png

     

    This is 100% ScriptUI-based.

     

    Note that the decimal point appears as a 'comma' because I've just executed the script in a French-localized InDesign version, but since the framework offers automatic localization it will turn commas into dots in English locales.

     

    The measurement edit controls have of default 'display unit' (which you can easily customize) but they all support every other units the user could enter on the fly. For example, the first control is hardcoded this way within the entire dialog structure:

     

    $$.RichEdit({text:"", decimals:0, unit:'pc', step: .5, minValue:-50, maxValue:50, caption: "First field (pc):", active: true,

                        helpTip:__("Enter the value using whatever unit. The result is formatted in pc with no decimals. Increment: 0.5 (=p6).")})

     

    UP and DOWN arrow keys are implemented. Also, an automatic min-max validation routine is implemented, so that you get such popup message:

     

    http://www.indiscripts.com/blog/public/ScriptUIMetricControls2.png

     

    Below is a link to the full sample script. (The framework by itself is partially included as a jsxbin at the very beginning of the script, but the client code is clear.)

     

    http://www.indiscripts.com/blog/public/ScriptUIMetricControls.js

     

    Feel free to try.

     

    @+

    Marc

     
    |
    Mark as:
  • Currently Being Moderated
    May 19, 2012 2:48 AM   in reply to Dan Rodney

    Dan,

     

    Maybe Bob is right, but with every release something is added or fixed in ScriptUI, so it's always worth filing feature requests. That said, ScriptUI seemed a bit out of Adobe's favour when alternatives like PatchPanel were introduced, but never seemed to make it. Anyway, the more feature requests are posted the more chance there is of further improvement.

     

    As to your other points: my unit convertor indeed didn't like p6 because it hadn't occurred to me that you could enter a value like that (I rarely use picas myself). But it was easy to fix (check the input; if it starts with "p", prefix "0"). I should post that thing separately. Math in edit boxes, too, can be implemented. It's not very complicated in principle, it just takes some coding. Your point 4, maximum and minimum values, are easily implemented, too, as e.g. Marc already did.

     

    One advantage of writing your own code is that you can do things that Indesign doesn't do natively. For instance, in the interface, the Shift key magnifies the cursor key's increment by a factor 10. So if you set the cursor key increment set to 0.1 point in the preferences you can switch easily between 0.1-point and 1-point increments, but nothing else. In a script you can add the Alt key (or its Mac equivalent) to use an additional magnification, say 0.1 points. In some scripts I use 1-point increments for unmodified keys, 10-point increments for Shift+arrow and 0.1 points for Alt+arrow.

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    May 19, 2012 5:51 AM   in reply to Dan Rodney

    Dan,

     

    > I'd personally like it to keep the native InDesign feel, as opposed to your custom

    > look that doesn't feel like either Mac or Windows.

     

    Well, I'm aware that this is what reduces the 'shareability' of my framework. I designed a 'default' skin which is applied to any custom components. However, the client code can supersede anything and, in fact, you even can still use the native OS look-and-feel. For example, to get this (Mac screenshot):

     

    http://www.indiscripts.com/blog/public/ScriptUIMetricControlsNativeSkin.png

     

    you need to replace my original client code by something like this:

     

     

    // SAMPLE DIALOG
    // ---
    var    u,
        w = $$.scriptui.createWidget([
                ['dialog', u, u, {text: " Measurement Edit Controls", background:-1}],
                {
                _0: $$.Group( {orientation: 'column'},
                    {
                    e1: $$.RichEdit({text:"", decimals:0, unit:'pc', step: .5, minValue:-50, maxValue:50, caption: "First field (pc):", active: true,
                            helpTip:__("Enter the value using whatever unit. The result is formatted in pc with no decimals. Increment: 0.5 (=p6).")}),
                    e2: $$.RichEdit({text:"", decimals:2, unit:'mm', step: .25, minValue:0, maxValue:300, caption: "Secund field:",
                            helpTip:__("Enter the value using whatever unit. The result is formatted in mm with 2 decimals. Increment: 0.25.")}),
                    e3: $$.RichEdit({text:"", decimals:1, unit:'%', step:5, minValue:0, maxValue:100, caption: "Percent field:",
                            helpTip:__("Enter a percent number. Increment: 5.")}),
                    bCancel: [ ['button',undefined,undefined,{text:__("Cancel")}] ],
                    }),
                }]);
     
    w.bCancel.onClick = function(){w.hide();};
    w.show();
    

     

    It's a bit complicated because I didn't implemented any API to easily address native ScriptUI widgets—which was not my original purpose.

     

    Note that the $$.RichEdit component still mimicks measurement edit controls as previously described, except that you won't get validation 'popups' anymore. Indeed, popup is a functionality of the $$.RichDialog component which I don't use in the above code.

     

    The whole code is available here:

    http://www.indiscripts.com/blog/public/ScriptUIMetricControlsNativeSki n.js

     

    [As Peter said, customizing keyboard events to address Shift/Alt + arrow keys is really not a problem.]

     

    @+

    Marc

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    May 21, 2012 6:30 AM   in reply to Dan Rodney

    Hopefully Bob will chime in, but:

    That's sad to hear. Can you shed some light as to why? It seems to me that measurementedits are an essential was to interact with scripts. All the "you can just script it yourself" talk is just a workaround for the lack of a real solution from Adobe. They were in the old scripting style dialogs, why not ScriptUI? It just seems strange to me that InDesign uses natively uses measurementedit-style fields all the time (and is an important aspect of the UI), yet they aren't available now in the "newer and better" ScriptUI.

    Adobe isn't showing any signs of doing further development in ExtendScript; quite the reverse, they're devoting substantial resources to ActionScript3 and CSSDK and Extension Builder. Even with Flash's lack of market future, it doesn't really look like this is changing.

     

    (I find this fairly frustrating since despite all the suggestions to the contrary, I find ActionScript rather less pleasant to work in that ExtendScript.)

     

    I think there's also something about how ExtendScript and ScriptUI are shared code across the creative suite, but measurement edit boxes are somewhat InDesign-specific.

     
    |
    Mark as:
  • Currently Being Moderated
    May 21, 2012 3:22 PM   in reply to Dan Rodney

    Flex has a NumericStepper component which can be modified to display any kind of measurements.

     

    Harbs

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points