Open UCL from script.

Help with writing and running scripts

Open UCL from script.

Postby chrispy35 » Tue Aug 14, 2007 9:23 pm

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.
User avatar
chrispy35
Newbie
 
Posts: 3
Joined: Mon Jul 30, 2007 11:00 pm

Re: Open UCL from script.

Postby Mofi » Wed Aug 15, 2007 6:49 am

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4062
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Open UCL from script.

Postby chrispy35 » Thu Oct 18, 2007 5:23 pm

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.
User avatar
chrispy35
Newbie
 
Posts: 3
Joined: Mon Jul 30, 2007 11:00 pm

Re: Open UCL from script.

Postby jorrasdk » Thu Oct 18, 2007 8:57 pm

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;
}
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: Open UCL from script.

Postby chrispy35 » Thu Oct 18, 2007 9:31 pm

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.
User avatar
chrispy35
Newbie
 
Posts: 3
Joined: Mon Jul 30, 2007 11:00 pm


Return to Scripts