8 Replies Latest reply: May 21, 2012 3:22 PM by Harbs. RSS

    [JS] ScriptUI and MeasurementEditboxes

    Dan Rodney Community Member

      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

        • 1. Re: [JS] ScriptUI and MeasurementEditboxes
          Bob Stucky Adobe Employee

          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

          • 2. Re: [JS] ScriptUI and MeasurementEditboxes
            Marc Autret MeganK

            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

            • 3. Re: [JS] ScriptUI and MeasurementEditboxes
              Dan Rodney Community Member

              Bob Stucky wrote:

               

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

               

              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.

               

              I'll have to take a longer look at your samples. As you say, they don't solve all the issues, but maybe they are a start.

               

               

              @Marc: Your example is interesting. It's good to know you can take things that far. I'm not sure I was looking for a complete framework that goes so far as to completely build the UI for me, but that is an interesting approach. While I was originally thinking of something to simply add the features to a standard edittext, I suppose that could work. 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. I'd be interested in seeing the code behind the validation logic you are using, which seems very good.

               

              Also, you pointed out a 4th issue that I didn't even think to add to my original post:

               

              4. Min and Max limits: We should be able to specify minimum and maximum values.

              • 4. Re: [JS] ScriptUI and MeasurementEditboxes
                pkahrel CommunityMVP

                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

                • 5. Re: [JS] ScriptUI and MeasurementEditboxes
                  Marc Autret MeganK

                  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/ScriptUIMetricControlsNativeSkin.js

                   

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

                   

                  @+

                  Marc

                  • 6. Re: [JS] ScriptUI and MeasurementEditboxes
                    John Hawkinson Community Member

                    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.

                    • 7. Re: [JS] ScriptUI and MeasurementEditboxes
                      Dan Rodney Community Member

                      @JohnHawkinson Arg, that's not good news, but I wouldn't be surprised. I MUCH prefer ExtendScript as well. In part because the interface works and feels more native. As a user I've always disliked the panels built with Flash. They typically have small differences from native UIs that create problems or annoyances.

                       

                      Because I've never looking into the CSSDK and Extension Builder, do they have some sort of measurement edit boxes that will at least make me happy if I switched? Or is it the same deal as ScriptUI, that I must write the feature myself?

                      • 8. Re: [JS] ScriptUI and MeasurementEditboxes
                        Harbs. CommunityMVP

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

                         

                        Harbs