Scripting command matchBrace() not working on other than active file

Scripting command matchBrace() not working on other than active file

1
NewbieNewbie
1

    May 11, 2012#1

    Greetings all,

    I am trying to write a script that will read a line from one opened document (SetsNeeded) and look for it in another opened document (OrderSets). Then it looks up for the beginning of the record, selects and copies the entire record, then pastes to a newly created file. The code below works up to the matchBrace() and I cannot figure out why. Any thoughts?

    Code: Select all

    var set = " ";
    UltraEdit.newFile();
    UltraEdit.clearClipboard();
    WorkingFile = UltraEdit.activeDocument;
    OrderSets = UltraEdit.document[0];
    SetsNeeded = UltraEdit.document[1];
    SetsNeeded.top();
    OrderSets.top();
    SetsNeeded.key("HOME");
    SetsNeeded.startSelect();
    SetsNeeded.key("END");
    SetsNeeded.copy();
    set = UltraEdit.clipboardContent;
    OrderSets.findReplace.find(set);
    OrderSets.findReplace.searchDown = false;
    OrderSets.findReplace.find("[CChartDataRepository,BulkLoad");
    OrderSets.key("HOME");
    OrderSets.matchBrace();
    OrderSets.copy();
    WorkingFile.write(set+"\r\n");
    WorkingFile.paste();
    This would be a file of many order sets.

    Code: Select all

    [CChartDataRepository,BulkLoad
      (OrderSetName1)  
        ]
    [CChartDataRepository,BulkLoad
      (OrderSetName2)
        ]
    [CChartDataRepository,BulkLoad
      (OrderSetName3)  
        ]
    [CChartDataRepository,BulkLoad
      (OrderSetName4)
        ]
    This is what I would be a list of sets I wanted to extract or copy out of the main file.

    Code: Select all

    OrderSetName1
    OrderSetName2

    6,675585
    Grand MasterGrand Master
    6,675585

      May 11, 2012#2

      Okay, I looked into it and found out that Match Brace command is simply working only on active file. That should not be the case and I will report it by email to IDM.

      As workaround you can use following script which I think does what you want.

      Code: Select all

      var set = " ";
      //UltraEdit.newFile();
      UltraEdit.selectClipboard(9);
      UltraEdit.clearClipboard();
      UltraEdit.document[0].setActive();
      OrderSets = UltraEdit.document[0];
      SetsNeeded = UltraEdit.document[1];
      OrderSets.top();
      SetsNeeded.selectAll();
      var asSets = SetsNeeded.selection.split("\r\n"); 
      if (asSets[asSets.length-1] == "") asSets.pop();
      SetsNeeded.top();
      OrderSets.findReplace.mode=0;
      OrderSets.findReplace.matchCase=false;
      OrderSets.findReplace.matchWord=false;
      OrderSets.findReplace.regExp=false;
      OrderSets.findReplace.searchInColumn=false;
      for (var nSetIndex = 0; nSetIndex < asSets.length; nSetIndex++) {
         OrderSets.findReplace.searchDown=true;
         OrderSets.findReplace.find(asSets[nSetIndex]);
         OrderSets.findReplace.searchDown = false;
         OrderSets.findReplace.find("[CChartDataRepository,BulkLoad");
         OrderSets.key("HOME");
         // UltraEdit.document[0].setActive();
         OrderSets.matchBrace();
         // UltraEdit.document[0].setActive();
         UltraEdit.clipboardContent += asSets[nSetIndex] + "\r\n";
         OrderSets.copyAppend();
         UltraEdit.clipboardContent += "\r\n";
      }
      UltraEdit.newFile();
      UltraEdit.activeDocument.paste();
      UltraEdit.clearClipboard();
      UltraEdit.selectClipboard(0);
      If there is never a ] between [CChartDataRepository ... ], or the context of matching ] can be used to identify this closing square bracket as the matching square bracket, it would be possible to use a regular rexpression Find instead of Match Brace command for selecting the block of interest. Well, a regular expression Find could be also used to select with a single Find the entire block containing the string of interest. No need to find downwards, then find upwards, then find downwards again.

      The problem with Match Brace command not working on other files than active file was confirmed by IDM support and added to their problems database for the developers to investigate.