Open UCL from script.

Open UCL from script.

3
NewbieNewbie
3

    Aug 15, 2007#1

    Hi there,

    Is there any way to open UCL from a script with the files to compare passed as parameters in the script?

    Here is what I'm trying to do...

    I have two files:
    fpga\mod_1\rtl\ram.vhd
    asic\mod_1\rtl\ram.vhd

    If I have one of these open in UltraEdit, I would like to be able to automatically compare it to the other without having to either open both files in UE first or to cut/paste/modify the 2nd filename in the UCL dialog first.

    Do this seem possible? I can't find any way to do it.

    Chris P.

    6,612548
    Grand MasterGrand Master
    6,612548

      Aug 15, 2007#2

      UltraCompare Lite can be only launched by UltraEdit. So what you want is possible only with UltraCompare Professional. With UCL you must specify both files in the dialog. No script or macro can help you here.
      Best regards from an UC/UE/UES for Windows user from Austria

      3
      NewbieNewbie
      3

        Oct 18, 2007#3

        OK, I've upgraded to UC Professional now but I think I've hit another road block:

        Is it possible to open UC Pro from a script while passing the filenames of both files to be compared? The UltraEdit.runTool method doesn't seem to do what I want as I can't pass two filenames to the tool (only the active document filename can be passed).

        Is there some other way to launch UC Pro from a script? Should I be trying to implement this in a macro instead?

        Thx,

        Chris P.

        262
        MasterMaster
        262

          Oct 19, 2007#4

          No neither scripts nor macros have commands to invoke UC directly. Your idea with UltraEdit.runTool() seems to be the only solution. Parameters can't be passed directly as you point out.

          But here is a script that are able to pass on two filenames as well as your preferred command line switches for UC Pro.

          The trick is to construct a complete line with parameters for UC in a new file and select it. Selected text can be passed on to a tool using %sel%

          I write futher comments in the script itself. I hope it works for you. (I have not UC installed myself but have tested against Beyond Compare which have a command line syntax that somewhat resembles UC).

          Code: Select all

          // Create two file paths from current file and
          // invoke UC using a tool and dynamic parameter %sel%
          
          // Define the folders where files to be compare reside:
          var path1 = "fpga\\mod_1\\rtl\\";
          var path2 = "asic\\mod_1\\rtl\\"
          
          // Define preferred UC command line switches:
          var cmdSw = "-t -i";
          
          // Get current file and path
          var currentFilepath = UltraEdit.activeDocument.path;
          
          // Get file index so we can restore the active tab
          var restoreFileIx = getActiveDocumentIndex();
          
          // Simple extraction of filename (assume windows path):
          var fileName = currentFilepath.substr(currentFilepath.lastIndexOf("\\") + 1);
          
          // Now open a new temp file and write UC command line input for %sel%
          UltraEdit.newFile();
          
          // Write command line switches:
          UltraEdit.activeDocument.write(cmdSw);
          
          // Write first file in quotes
          UltraEdit.activeDocument.write(" \""+path1+fileName+"\"");
          
          // Write second file in quotes
          UltraEdit.activeDocument.write(" \""+path2+fileName+"\"");
          
          // Now select the whole line to make it available for %sel%
          UltraEdit.activeDocument.gotoLineSelect(1,1);
          
          // Then run the tool invoking UC
          // The command line of the tool should look something like:
          // start uc %sel%
          // Configure as DOS command because we use "start" so we will not wait for UC.
          // UC must be in the DOS PATH
          // Uncheck options: Save active file, capture output.
          UltraEdit.runTool("UC");
          
          // Close the temp file without saving
          UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
          
          // Restore original file as active
          UltraEdit.document[restoreFileIx].setActive();
          
          // Helper function to find the tab index of the active document 
          function getActiveDocumentIndex() {
          	var tabindex = -1; /* start value */
          
          	for (i = 0; i < UltraEdit.document.length; i++)
          	{
          		if (UltraEdit.activeDocument.path==UltraEdit.document[i].path) {
          			tabindex = i;
          			break;
          		}
          	}
          	return tabindex;
          }

          3
          NewbieNewbie
          3

            Oct 19, 2007#5

            Excellent! It works great.

            Just to note, when I select UC as a Windows program in Tool Configuration, I get an "Error opening file for write: The operation completed successfully" message box when I run the script.

            Selecting UC as a DOS program produces no such error.

            Thank you so much for the quick reply.

            Chris P.