Is Anyone Using that Command?
by Mark Stefanchuk, CADmanage.com
As a CAD Manager I often wonder if I’m focusing on the right things. I don’t know if anyone else ever has this issue, but I often think, as I’m updating a program or some documentation, if anyone is even using the thing.
If the number of CAD users is less than twenty, you can just ask everyone if they are using the command. It’s tedious but manageable. When you have hundreds of users however, asking everyone is not practical. So, what do you do? Just go ahead and update it anyway? Or, like some of our colleagues might do, just leave it out of the mix next time you upgrade the CAD engine and wait for someone to scream, “Hey, what happened to <insert favorite command here>”. It’s a dangerous approach, but sometimes you just have a feeling that the add-on, plug-in, or whatever is obsolete.
I think we can be a little more pro-active. If it’s your code and you still have the source you can insert a bit of code to write a log file each time the command is run. This is a good approach, especially for multi-platform environments. I’ll describe how to do this, but first let’s look at a quick way to capture command use on your AutoCAD platform without writing code.
AutoCAD – The Log File:
Yes, that’s right. Turn on the log file option. There’s going to be lots of files and lots of junk that you don’t need, but you’re only looking for one instance of the command to validate that the thing is being used. You turn on the log file option by opening the options dialog (command options). Click on the open and save tab and check the “Maintain a Log File” option.
Set the location of the log files, Options > Files > Log File Location,
I can’t really predict what the lasting ramifications are for doing this. The files aren’t really that big, but if you have a large number of users all writing log files to the same location then you might not want to be using up disk space for this. So, after you’re done collecting data turn off the use log file options.
The log files contain the commands your users have recently run. Now you need a quick way of searching the files. Grep for Windows is a good tool to use. Download the open source gnu version from here,
On my 64bit Windows 7 computer Grep.exe is installed to C:\Program Files (x86)\GnuWin32\bin\. Add the location of this program to your system path.
The basic usage is
grep <pattern> <files to search>
When I searched on the command “_qsave” grep found 2 instances – not a big surprise. It will also work when you want to find out if that older command has been used recently. If grep does not return a result then you may be able to conclude that the command is no longer needed.
To be more certain that a program is no longer in use, run this process over the course of several weeks. There are probably several old programs that you can eliminate from the maintenance cycle. So, log files and grep create a quick and fairly easy way to run an audit without having to write a bunch of code.
Write Some Code:
You have many choices when you commit to writing some code, but I’m going to keep it simple and stick with VBA. It’s a common platform for both MicroStation and AutoCAD and will give us an opportunity to re-use some code. I’m also just going to output to a text file. You can then grep or edit the file a few times during your audit period to find out if the command you’re interested in is being used. We can get much more sophisticated, but for a quick test this will work. Insert the following function in your VBA.
Public Function reportCommand(sCmd As String, sFile As String) As Boolean
Dim fnum As Integer
reportCommand = False
On Error GoTo ERRORHANDLER
fnum = FreeFile ' get next available file number
' report command usage
Open sFile For Append As #fnum
Print #1, sCmd
reportCommand = True
'Debug.Print "reportCommand: " + err.Description
And in the macro sub you are interested in, add a call to this function.
Public Sub ACADCmd()
Call reportCommand("tempcmd", "c:\temp\test.txt")
' . . .
' run/initialize something
' . . .
All we’re doing here is writing a string, sCmd to a text file specified by SFile (example: C:\temp\test.txt).
What I like most about this approach is that you can use the code in any CAD system that supports VBA. For instance, I developed the code in MicroStation, but cut and pasted it into my AutoCAD VBA without making any changes. The call to the function looks the same in both environments too. You can take this a step further by building a re-usable library, but we’ll save this topic for a future post.