1 Reply Latest reply on Jun 25, 2008 6:03 AM by sotospeak (carlo bazzo)

    ScriptUI basic question part 2

    sotospeak (carlo bazzo)
      After Bob's suggestions I still have same problems, I open a new topic to be clear. This is the core part of my script:
      #target indesign
      #targetengine 'mysession'
      res ="palette { alignChildren: 'fill', \
      info: Panel { orientation: 'column', alignChildren:'right', \
      text: 'Scelta del Codice', \
      name: Group { orientation: 'row', \
      s: StaticText { text:'Codice:' }, \
      whichCode: DropDownList { alignment:'left' }, \
      s: StaticText { text:'Preview Prezzo:' }, \
      e: EditText { characters: 5 } \
      } \
      }, \
      buttons: Group { orientation: 'row', alignment: 'right', \
      okBtn: Button { text:'OK', properties:{name:'ok'} }, \
      cancelBtn: Button { text:'Cancel', properties:{name:'cancel'} } \
      } \
      }";
      var mydocument=app.documents.item(0);//my opened doc
      win = new Window (res); win.center(); win.show();
      var myItems=myReadXMLPreferences();//to load my dropdown whichCode

      if (myItems!=""){

      with(win.info.name){

      for(var myCounter = 0; myCounter < myItems.length(); myCounter++){

      var s_item=whichCode.add('item',myItems[myCounter].xpath("codice"));}

      }
      }

      win.buttons.okBtn.onClick = function(){

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

      creatagselection(xmltag);

      }
      function myReadXMLPreferences(){

      myXMLFile = File.openDialog("Choose the file containing your button bar defaults");

      var myResult = myXMLFile.open("r", undefined, undefined);

      var myItems = "";

      if(myResult == true){

      var myXMLDefaults = myXMLFile.read();
      myXMLFile.close();
      var myXMLDefaults = new XML(myXMLDefaults);
      var myItems = myXMLDefaults.xpath("/root/item");
      }
      return myItems;
      }

      function creatagselection(xmltag) {
      if (app.selection.length == 1){//there is a textframe selected
      if (app.selection[0].constructor.name=="TextFrame") {
      //it seems I get here but not beyond
      var myXMLTag=mydocument.xmlTags.add(xmltag);
      //put an alert here but never executed
      var myXMLElementA = mydocument.xmlElements.item(0).xmlElements.add(myXMLTag);
      myXMLElementA.contents = "Test "+xmltag;
      var mytextframe=app.selection[0];
      myXMLElementA.markup(mytextframe);
      }
      }
      }

      I had the same creatagselection function in a dialog and it is working so that I have my textframe tagged. When executed I do not have any errors but my selected texframe results always untagged.
      I suppose I miss something about ScriptUI..any help welcome thank you

      carlo
        • 1. Re: ScriptUI basic question part 2
          sotospeak (carlo bazzo) Level 1
          I got the problem: my tag list loaded in the whichCode dropdown by the myReadXMLPreferences function has some items beginning with numerical chars (example: 1ACDE) and they are not allowed as tags (I did not remember this limitation). If I choose an alphabetic first char code from the list the script is working.

          I think I should filter the list putting a string before any numerical code.