Tuesday, October 21, 2008

Set part class dimensions

As far as the QUEST online documentation shows, there is no BCL command for setting a part class' dimensions.

I thought it would be possible to do this by exporting a part class to a text file, modifying the text file with the new dimensions, and then re-importing the text file to overwrite our part class with the new dimensions.

Here is the resulting SCL macro.

You can use it from within SCL by calling set_pclass_dimensions with a handle to the part class, then the 3 arguments to set the part class dimensions to.

You can call it from a BCL script using the following commands, setting the full path to the set_pclass_dimensions.scl file, substituting Part1 with the name of the part class you want, and setting the dimensions to the sizes you want:

SCL_COMPILE 'set_pclass_dimensions.scl' 0
SCL_EXEC set_pclass_dimensions_by_name WITH ARGUMENTS 'Part1' , 100 , 200 , 300

SCL Subroutine Indexer

If you're anything like me, you've written a large variety of SCL logics and have tons of procedures and routines buried in files which are in turn buried in different QUEST LOGICS and SCLMACROS libraries.  Sometimes I need a logic that I know I've already written, but can't remember where it is.  I use Google Desktop to find files, but it is unable to search within the text of a plain text file unless it has an extension it recognizes (i.e. not .scl).

Rather than write a plugin for Google Desktop to enable SCL search, I went the quicker, dirtier, and easier path (for me, anyway) and wrote a couple macros in Excel to index a set of SCL files (extracting all procedure and routine declarations) into an Excel worksheet.  A while back I wrote an interface for Excel's AutoFilter that makes setting filters on large datasets a little easier than without.

One thing to note is I haven't set it up to read any subroutine declarations that span multiple lines (using the line continuation character "\") so at the moment it won't pick up the full declaration.

Updated:  10/21/08 - Modified the auto-filter helper to run faster in populating the result list box for large data sets

To use this indexer, simply copy the SCL_Indexer.xls file to your computer, and open it in Excel.  I signed the VBA project with a digital certificate created on my own computer, so you should be able to import the certificate, but to be honest I'm not sure how that will work, and you may be stuck hitting "enable macros" every time you open the file.  If nothing else, you can try saving the file to a trusted location.

When you open the file (with macros enabled) the indexer will create a toolbar called "AutoFilterHelper".  This toolbar contains the buttons for running the indexer and searching the index (In Excel 2007 a section will be added to the Addins ribbon with the buttons).

To use the indexer just click on the binocular button.  This will open a form that allows you to select a directory or file, and to index it.  You may select to index any subdirectories from a directory.  Hit cancel while it's indexing if you want it to stop.

Once the index is built you will see that the worksheet is populated with all procedure and routines indexed, with the return type (Null means it's a procedure) and arguments listed.  The file name for each subroutine is listed as well.

To use the auto filter helper, click on the magnifying glass, and select the column header you want to search.  It may take some time to populate the result box, but you will see a list of all subroutine names in the bottom right box.  To search the list, start typing in the text box and the results in the result box will reflect what you've typed in the search box.

Select an item in the result box and click "Apply Filter" and that filter will be applied in the index worksheet.  For more information on auto filter: http://www.contextures.com/xlautofilter01.html

Monday, October 6, 2008

SCL Code "Profiler"

I've written a fairly large SCL macro, which you'll be able to get soon here.

In order to keep tabs on how much of this 8000+ line macro is real code, I decided to write an SCL logic "profiler", which really just goes through and counts the number of comment lines, blank lines, and everything else, and reports it out for you.  So really in my (currently) 8195 lines of code there's really 5978 lines of code, 1061 blank lines, and 1156 lines commented out.

The line counter code can be downloaded here.

Wednesday, October 1, 2008

String Replace

This routine gives you similar functionality to the replace function in VBA. Basically, the routine just reads through a string argument and replaces any instance of to_replace with replace_with.
As far as I can tell there is no built-in function in SCL for doing this...

routine replace_string( full_string : String ; to_replace : String ; replace_with : String ) : String
Var
   result : String
   start_idx : Integer
   rep_idx : Integer
Begin
   start_idx = 11
   result = full_string
   while( index( result , to_replace , start_idx ) > 0 ) do
      rep_idx = index( result , to_replace , start_idx )
      result = leftstr( result , index( result , to_replace , start_idx ) - 1 ) + replace_with + rightstr( result , len( result ) - index( result , to_replace , start_idx ) - len( to_replace ) + 1 )
      start_idx = rep_idx + len( replace_with )
   endwhile
   return result
End