Collector

A powershell script to merge source code files for Autocad and Inventor.
Code Powershell

Logo

This powershell script will recursively collect text files within a single directory and insert them into a single file. The trick is that you can specify which files to collect with a special tag in the first line of that document. Three tag variations allow you to perform different operations.

Collector is intended to allow you to organize your code in class-per-file or module-per-file file structures organization. It supports commenting out select lines during collection.

This tool was originally developed for use developing complicated Inventor iLogic routines and add-ins which may be tested tested in Inventor’s iLogic environment. It also works well for collecting Autocad Lisp routines into a single file. Though this tool maybe used for just about any source code file.

Source Code

You can find the project repo on github here: Collector

Find the powershell script itself here: Collector.ps1

A Simple Use Case…

If I’m developing a complex ilogic routine, let’s say a BOM export routine, I’ll probably choose to place my classes and interfaces in separate files. This follows .net best practices, and allows me to use Visual Studio (or another IDE) to manage my codebase. This provides intellisense, better project navigation, git integration, as well as other goodies. Collector lets me merge all of the desired files into a single ilogic routine that I can deploy to my CAD users. This also allows me to more easily transition the ilogic routine into a full-fledged add-in at a later date; most of the work is already done.

How To Use

Simply include tags into the source code files that you want to collect. You should comment these tags out for whatever source code you’re using. E.g. for VB, the tag would read '</Collector>, for AutoLISP it would read ;</Collector>.

Optional Parameters

When ready to compile, run this powershell script to combine the files into a single file. There are several optional command line parameters available.

-Watch : the directory to scan. The path may be relative to the script location or absolute. E.g. -Watch “src”, or -Watch “C:\dev\project" will only scan files within those directories.

-Out : Specifies the output file name that collector will generate. The path may be relative to the script location or absolute. The default “build/build.vb” filename is used if none is specified. This script will overwrite any file with that same name. If the file is currently open, it will need to be closed or deleted to proceed.

-Filter : an optional wildcard glob that will speed up the collection process by restricting the scanned files to matches. E.g. -Filter “*.vb” will instruct collector to only scan files ending in .vb.

User defaults for these parameters can be set within the file.

It is important to note that if the optional parameters are not set to absolute paths, the path relative to the script will be used as the basis for file paths.

Example

See the /Example/ folder for a simple set of code files that illustrates Collector in action. The Example.iLogicVB file has been generated by the Collector.ps1 script. The files “ExporterClass.vb”, “Main.vb”, and “SphereClass.vb” contain the Collector tags that tells the script what to do.

Troubleshooting

If you have difficulty running this commands, you may need to issue the command like so if permissions issues prevent running the powershell script. That said, I have chosen to leave this command as a powershell script instead of a C# executable so that users may read through the code and understand that it’s not doing anything malicious.

powershell -ExecutionPolicy ByPass -File .\Collector.ps1