Multiple Resources (AutoCAD)
by Mark Stefanchuk, CADmanage.com
Seth’s last blog, Resources Resources…, was great! In particular this bit of information really caught my attention.
The Files tab lists the folders that AutoCAD will use to search for resource files (a.k.a. Support Paths), drivers, CUI files, tool palettes, and so on. There are also user-defined settings such as the dictionary file used for checking spelling. Paths are searched in the order that they are listed in the Options dialog box, and if the same file exists in different folders, the first instance found is used.
Ok, so that got me thinking. How do I know if there is more than one file with the same name in my paths folders and is the file I want loaded in the right place? My first thought was to just look in each folder and see if there are duplicates. But, turns out there are a lot of files in these folders. I’m going to need a better way. I could write a vb script to look in each support folder and compare all of the files dumping the results to some output file, but I kind of want to be able to debug my profile folders when I’m in AutoCAD. To do that we will need a different approach.
I decided to build a plug-in. If you’re not familiar with .Net plugins for AutoCAD check out Autodesks “My First Plug-in” tutorials. Really well done. You don’t need the wizard, and you can find the AutoCAD references in the AutoCAD program files folder. There are a lot of on-line tutorials for VB.Net or C# – either programming language can be used to create an AutoCAD plugin. I’ll let you do your own googling to find what you need.
Here are some pointers for getting the support file information from AutoCAD. We will start by just figuring out what our support files are.
Your class will need to reference and Import the following:
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.Interop
In your class you will need a new command to show the support paths.
<CommandMethod("SHOWSP")> _ Public Shared Sub ShowSupPaths() Dim acadApp As AcadApplication = Application.AcadApplication MsgBox(acadApp.Preferences.Files.SupportPath) End Sub
Compile this to create a dll that you can netload (just like in the plug-in tutorials). After you netload you can use the command SHOWSP which will display a message box similar to this one.
It’s not very pretty and you can find the same information using the built in OP (options) command. So, what we really want is to get a list of file names from each folder and then compare them to one another to see if they show up more than once. What can we do? The first thing to notice is that the support paths are separated by a semi-colon. That gives us a way to “split” the string into an array of folders. We can then use System.IO to get directory info which we can use to list the file names. Something like this…
Dim sPaths() As String sPaths = acadApp.Preferences.Files.SupportPath.Split(";") For Each s As String In sPaths Dim di As DirectoryInfo = New DirectoryInfo(s + "\") For Each f As FileInfo In di.GetFiles() lstFiles.Items.Add(f.Name) Next Next
In this example I have added the file names to a list box. You can loop through the list items to check for duplicates and output to another list box. I took it a step further and built a Palette. In the top panel I added a tree view so that I have a way to step though the folders and files. In the bottom panel I list the files that show up more than once.
I also added a double click feature to open a window and select the file in the folder it resides in so that I have a quick way to compare files. Finally, I decided to add an extension filter so that I can debug just cuix, or lsp files.
We’re looking into posting this on the Autodesk Exchange. So, if you don’t want to dig deeper and try to write it yourself I hope to have this submitted and available in the next few weeks.
About Mark Stefanchuk: Mark is a VP and senior consultant with CAD Management Resources, Inc. He divides his time between developing innovative custom software solutions and helping clients navigate complex design automation environments. If you would like to find out how he can assist you with your design technology he can be reached by contacting us at email@example.com.