Home » Scripting, XSI

Debugging made easier

22 December 2005 6,663 views No Comment

The hyperlinks generated in the Script Editor when an script error is thrown can be very helpful in finding exactly where a problem has occurred. The only issue is that if you are using an external editor, the line number is not communicated to the editor to make it automatically scroll to the line of code that produced the error.

Most standalone text editors allow for a command line parameter to indicate which line number to position the cursor when opening a new file. By making a quick change to one of XSIís scripts, we can communicate this to the external editor. To make this change, follow the steps below.

(By the way, I take no responsibility if something goes wrong and you have to reinstall XSI to get everything working again!)

  1. Navigate to
        C:SoftimageÖApplicationCommands
  2. Create a backup copy of "SDKHelpers.js" and call it something like "SDKHelpers.js_backup".

    Note: it is important to change the file extension to something other than "js" as otherwise it will try to install the same commands twice and youíll get a conflict.

  3. Navigate to line 106. It should be inside the ìShowFileForEdit_Executeî function at the line which says :
        if ( -1 != strExternalEditor.search( /%s/ ) ) 
  4. Replace everything inside that "if" clause, i.e:
        // (Mis)use the XSIUtils.Translate() API
        // to replace a %s token in the string with the file
        // name.  This gives us lots of flexibility for supporting
        // different command line options for showing an external editor
    
        strCmd = XSIUtils.Translate( strExternalEditor, "None", in_file ) ;
        logmessage( "Launching " + 	strCmd, siVerbose ) ;
        XSIUtils.LaunchProcess( strCmd, false ) ;
    

    With this:

        strExternalEditor = strExternalEditor.replace(/%s/,in_file);
        if ( strExternalEditor.search( /%l/ ) != -1)
        {
            strExternalEditor = strExternalEditor.replace(/%l/,in_linenum);
        }
        XSIUtils.LaunchProcess(strExternalEditor);
    
  5. Save the file and restart XSI.

You can now use %l (thatís a lowercase L) in the filename for your external editor to pass the line number at the correct position in the command line options. Note that the original script already allowed for a %s parameter to be passed as a location to insert the filename to edit, and we have retained that functionality.

So for example, for JEdit you would use this in the external editor setting in the Script Editor Preferences:

    c:jeditjedit %s +line:%l

Personally, I use Crimson Editor, and my external editor setting is:

    C:Program FilesCrimson Editorcedt.exe /L:%l %s

Now if a script throws an error, you can click on it and your external editor will open the file at the correct line. This should make it a lot easier to use your external editor with XSI.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.