9 Replies Latest reply on Jul 7, 2008 4:47 AM by Peter Kahrel

    ScriptUI basic question

    sotospeak (carlo bazzo)
      I have created a palette but when I press OK I can not have any actions performed on the active document. My code for the OK button onClick event:

      win.buttons.okBtn.onClick = function(){
      var xmltag=win.info.name.whichCode.selection;//a string
      var myXMLTag=mydocument.xmlTags.add(xmltag);//no error but xmltag not added
      var myXMLElementA = mydocument.xmlElements.item(0).xmlElements.add(myXMLTag);
      myXMLElementA.contents = "Test "+xmltag;
      var mytextframe=app.selection[0];//a textframe is user selected
      myXMLElementA.markup(mytextframe);
      }

      I think I did not grasp how scriptUI interfaces communicate with active documents. Thank you

      Carlo Bazzo
        • 1. Re: ScriptUI basic question
          Level 1
          Your approach seems fine. You need to change the first line:

          var xmltag = win.info.name.whichCode.selection.text;

          selection is not text...

          My times errors encountered in a ScriptUI handler will not be propagated.

          As a style tip, I try to avoid having that much code in a handler. I create a function to do the work, and call it from the handler, typically passing it the reference to the window.

          tagIt = function( win ) {
          ... your code here
          }

          The handler becomes:

          button.onClick = function() {
          tagIt( this.window );
          }

          If you do that, you can, from a script call the tagIt function to debug it. It's much, much easier that way.

          Regards

          Bob
          • 2. Re: ScriptUI basic question
            Level 1
            Hi Carlo,

            You could also look at the AddGuides.jsx example script that came with CS3--it has a ScriptUI dialog in it.

            Thanks,

            Ole
            • 3. Re: ScriptUI basic question
              sotospeak (carlo bazzo) Level 1
              thank both of you.

              Some free notes after your kind replies:

              -Of course selection is not a string: I was so doubtful about the way my palette could act on documents that I missed an easy one, thanks Bob

              -I am quite an aged Python programmer but I have only a couple of days experience in Indesign object models. I had an urgent request from a customer and I had to dive into coding quite in a hurry.

              After reading the docs I am a bit confused about one thing: it seems you can have "ordinary" dialogs and ScriptUI dialogs. While the latter choice seems far superior I was wondering why you should have two families of classes which erroneously appear similar but often have complete different attribute and properties. Can you explain to me this kind of dichotomy in Adobe scripting?

              Another question is about books. We have several books about every Adobe application, we have thousands of books about Office scripting but I did not find any about Adobe scripting, just some pages on the various Indesign bibles..It is clear looking at this forum there are some extremely skilled people: why Adobe did never ask you to write a good book about Indesign scripting? One could think Adobe has not a great interest in sharing too many technical details..
              • 4. Re: ScriptUI basic question
                Level 1
                Hi Carlo,

                re: "After reading the docs I am a bit confused about one thing: it seems you can have "ordinary" dialogs and ScriptUI dialogs. While the latter choice seems far superior I was wondering why you should have two families of classes which erroneously appear similar but often have complete different attribute and properties. Can you explain to me this kind of dichotomy in Adobe scripting?"

                First, ScriptUI is JavaScript-only. InDesign supports AppleScript and VBScript, and the InDesign dialog object exists to make it easier for scripters using those lanugages to create simple dialogs (actually, I'd argue that the dialog object is far superior to ScriptUI for simple modal dialogs).

                Second, we added the dialog object in a version of InDesign before the ScriptUI library was available.

                re: "It is clear looking at this forum there are some extremely skilled people: why Adobe did never ask you to write a good book about Indesign scripting? One could think Adobe has not a great interest in sharing too many technical details.."

                What are the specific failings of the InDesign Scripting Guide(s) for CS3? I realize they're not perfect, but I can and will make them better.

                Thanks,

                Ole
                • 5. Re: ScriptUI basic question
                  sotospeak (carlo bazzo) Level 1
                  Thank you Olav I have a better perspective now. This forum is undoubtfully one of the most competent in the net and make me feel eager for getting to know Adobe scripting better.

                  As it regards the scripting book I did not like to mean I do not appreciate your scripting guides: I think they are one of the best software documentation I have ever seen, but nonetheless I think it is a very strange strategy not having something published about scripting which, by the way, it is easy to say would be a great selling success.

                  I would not wish to waste your time but I can not help asking you if there is any present or planned connection between Adobe scripting and Python; with respect to this I read ScriptUI has some asynchronous communication possibilities: any chance to have an "ajax" call to retrieve some data from a server side (Python) script?

                  Thank you for your great job here,

                  carlo
                  • 6. Re: ScriptUI basic question
                    Emanuele Radaelli Level 1
                    Hello everybody!

                    First time with UI in ID CS3... and it's really a bit difficult to me.
                    I'm trying to reproduce the JPG exporting interface (without options, which are setted within the script).
                    I have 2 radio buttons, one to export all pages and the other to export just a range defined by the user (so, when this one's checked the EditText becomes active...).
                    First step: I create a group which contains the radio buttons but I can't check the right one because both are selected.
                    That's the script:

                    sel =
                    "dialog { \
                    info: Panel { orientation: 'column', alignChildren: 'right', \
                    text: 'Seleziona le pagine da esportare', \
                    rb: Group { orientation: 'column', alignChildren: 'left', \
                    seleziona: Group { orientation: 'row', \
                    seleziona_rb: RadioButton { text: 'seleziona', value: 'false' }, \
                    seleziona_txt: EditText { preferredSize: [200,20]} \
                    }, \
                    tutto_rb: RadioButton { text: 'Tutte', value: 'true' } \
                    } \
                    }, \
                    buttons: Group { orientation: 'row', \
                    okBtn: Button { text:'OK', properties:{name:'ok'} }, \
                    cancelBtn: Button { text:'Cancel', properties:{name:'cancel'} } \
                    } \
                    }";
                    win = new Window (sel);
                    win.center();
                    win.show();

                    Sorry for my bad english, hope you unerstood.
                    Thanks in advance for your precious help!
                    • 7. Re: ScriptUI basic question
                      Level 1
                      when you add radio buttons, buttons that are to work together (meaning click one and the other deselects) have to be created one after the other. You are creating a text box between the two radio buttons. That's why it's not working for you.

                      Regards

                      Bob
                      • 8. Re: ScriptUI basic question
                        Peter Kahrel Adobe Community Professional & MVP
                        >it's really a bit difficult to me

                        Cheer up -- it's difficult for all of us :)

                        The radiobutton statements must be contiguous and in one group, otherwise they'll not function properly.

                        But it seems to me that radiobuttons aren't the most straightforward approach for what you want. Maybe a text edit box and a checkbox would be easier. The script could default to "Tutti" and use an event handler that unchecks the "Tutti" checkbox if you enter something in the "Seleziona" field.

                        Peter

                        [Bob beat me to it]
                        • 9. Re: ScriptUI basic question
                          Peter Kahrel Adobe Community Professional & MVP
                          Something strange is going on: Bob's response and mine first appeared in "UI radiobutton...", but were then moved to this thread.

                          Peter