Automatic loading of .NET modules
Clearly it’s far from ideal to ask your users to load your application modules manually into AutoCAD whenever they need them, so over the years a variety of mechanisms have been put in place to enable automatic loading of applications – acad.lsp, acad.ads, acad.rx, the Startup Suite, to name but a few.
The most elegant way to auto-load both ObjectARX and .NET applications is the demand-loading mechanism. This mechanism is based on information stored in the Registry describing the conditions under which modules should be loaded and how to load them.
Demand loading is fairly straightforward and well documented in the ObjectARX Developer’s Guide (look under “demand loading applications”).
Essentially the information can be stored in one of two places: under HKEY_LOCAL_MACHINE or under HKEY_CURRENT_USER. The decision on where to place the information will depend on a few things – mainly whether the application is to be shared across all users but also whether your application installer has the privileges to write to HKEY_LOCAL_MACHINE or not.
It’s not really the place to talk about the pros and cons of these two locations – for the sake of simplicity the following examples show writing the information to HKEY_CURRENT_USER. Let’s start by looking at the root location for the demand-loading information:
HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications
Most of this location is logical enough (to humans), although the “ACAD-5001:409” piece needs a bit of explanation. This number has evolved over the releases, but right now 5001 means AutoCAD 2007 (it was 4001 for AutoCAD 2006, 301 for AutoCAD 2005 and 201 for AutoCAD 2004), and 409 is the “locale” corresponding to English.
A more complete description of the meaning of this key is available to ADN members at:
Registry values for ProductID and LocaleID for AutoCAD and the vertical products
There are two common times to load a .NET application: on AutoCAD startup and on command invocation. ObjectARX applications might also be loaded on object detection, but as described in a previous post this is not something that is currently available to .NET applications.
Let’s take the two common scenarios and show typical settings for the test application shown in this previous post.
Loading modules on AutoCAD startup
Under the root key (HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications) there is some basic information needed for our application. Firstly, you need to create a key just for our application: in this case I’ve used “MyTestApp” (as a rule it is recommended that professional software vendors prefix this string with their Registered Developer Symbol (RDS), which can be logged here, but for in-house development this is not necessary – just avoid beginning the key with “Acad” :-).
Under our application key (HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\MyTestApp), we then create a number of values:
- DESCRIPTION A string value describing the purpose of the module
- LOADCTRLS A DWORD (numeric) value describing the reasons for loading the app
- MANAGED Another DWORD that should be set to "1" for .NET modules
- LOADER A string value containing the path to the module
The interesting piece is the LOADCTRLS value – the way to encode this is described in detail in the ObjectARX Developer’s Guide, but to save time I’ll cut to the chase: this needs to have a value of "2" for AutoCAD to load the module on startup.
Here's a sample .reg file:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\MyTestApplication]
"DESCRIPTION"="Kean's test application"
"LOADCTRLS"=dword:00000002
"MANAGED"=dword:00000001
"LOADER"="C:\\My Path\\MyTestApp.dll"
After merging it into the Registry, here's what happens when you launch AutoCAD:
Regenerating model.
Initializing - do something useful.
AutoCAD menu utilities loaded.
Command: tst
This is the TST command.
Command:
Loading modules on command invocation
To do this we need to add a little more information into the mix.
Firstly we need to change the value of LOADCTRLS to "12" (or "c" in hexadecimal), which is actually a combination of 4 (which means "on command invocation") and 8 (which means "on load request"). For people that want to know the other flags that can be used, check out rxdlinkr.h in the inc folder of the ObjectARX SDK.
Secondly we need to add a couple more keys, to contain information about our commands and command-groups.
Beneath a "Commands" key (HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\MyTestApp\Commands), we'll create as many string values as we have commands, each with the name of the "global" command name, and the value of the "local" command name. As well as the "TST" command, I've added one more called "ANOTHER".
Beneath a "Groups" key (HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\MyTestApp\Groups), we'll do the same for the command-groups we've registered our commands under (I used the default CommandMethod attribute that doesn't mention a group name, so this is somewhat irrelevant for our needs - I'll use "ASDK_CMDS" as an example, though).
Here's the the updated .reg file:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\MyTestApplication]
"DESCRIPTION"="Kean's test application"
"LOADCTRLS"=dword:0000000c
"MANAGED"=dword:00000001
"LOADER"="C:\\My Path\\MyTestApp.dll"
[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\MyTestApp\Commands]
"TST"="TST"
"ANOTHER"="ANOTHER"
[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\MyTestApp\Groups]
"ASDK_CMDS"="ASDK_CMDS"
And here's what happens when we launch AutoCAD this time, and run the tst command. You see the module is only loaded once the command is invoked:
Regenerating model.
AutoCAD menu utilities loaded.
Command: tst
Initializing - do something useful.This is the TST command.
Command:

Subscribe via RSS
I just wanted to say "Thank you" for going over this information...These past 3 posts have been great...Not being able to pay for ADN status has made it quite dificult to learn stuff like this...Just wanted to say keep up the good work!!!
Posted by: Ray Mendoza | September 11, 2006 at 11:39 PM
My pleasure - glad you're finding the information useful. :-)
Posted by: Kean | September 12, 2006 at 09:11 AM
Hi Kean,
First of all, I would like to thank you for the quality of your blog and your advices. Now, after automatic loading of .Net modules, my question concern the automatic loading of AutoCAD interfaces. Which possibility have we to load automatically an interface (.CUI Files) on AutoCAD startup ? If we can do it, it's finished. Cause we have the command and the interface ... How do you say in english ? The loop is looped !
Congratulations to you and your family for the young Zephyr !
Matthieu
Sorry for my poor english ... Next time it may be in french ;o).
Posted by: Matthieu Lefebvre | October 02, 2006 at 02:23 PM
Hi Matthieu,
Have you tried executing the CUILOAD command on startup? The classic way to do this is using the (s::startup) LISP function, defined in your acad.lsp file:
(defun-q MYSTARTUP( )
(command "_.cuiload" "mycustomfile.cui")
)
(setq S::STARTUP (append S::STARTUP MYSTARTUP))
I hope this helps,
Kean
Posted by: Kean | October 11, 2006 at 02:56 PM
Hello, thanks for the answer, it wanted to know as I can program equivalence to the AutoCAD command boundary (command “- Boundary” "" "") from Visual BASIC 2005, I have intensely looked for but nonencounter information on that subject, what desire to do is to indicate a point among other entities and to generate a contour or a region soon to obtain its area. Thanks. My name is Mario and my mail is mtorrespx@yahoo.es
Posted by: Mario | October 15, 2006 at 07:48 AM
Hi Mario,
This looks like a request for some custom code (unrelated to this post). I'd suggest posting your request to the AutoCAD .NET Customization discussion group (http://discussion.autodesk.com/forum.jspa?forumID=152) or via the ADN website, if you're a member.
To give a hint, I'd suggest using Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint() to get a point, which you pass to the boundary command, executed using one of the techniques described in this previous post: http://through-the-interface.typepad.com/through_the_interface/2006/08/calling_command.html.
Regards,
Kean
Posted by: Kean | October 16, 2006 at 04:30 PM
Thanks Kean
I 've already read about the post you told me, but I thought there was a way to make a boundary around the programation .net. I had read about generate loops.
regards,
Mario
Posted by: Mario | October 17, 2006 at 02:22 AM
Hi Mario,
The BOUNDARY command actually does quite a lot of hard work - it would be tough to replicate. I'm not entirely sure what loops you would want to create through the managed API - BOUNDARY creates polylines or regions... both of which you can create through the managed API, of course. But getting the analysis of existing geometry right could take a lot of effort.
Regards,
Kean
Posted by: Kean | October 17, 2006 at 11:19 AM
Hi Mario,
(Fist of all thanks, you are always the source of the best information)
I have an arx dll that has a startup function that writes a partial.cui into the acad.cui (Using CustomizationSection). Works great, but the menus just do not show up in the UI. The partial.cui existis in the CUI dialog but you literally have to manually load using cui or cuiload.
This is not what I want & it seams that the only other way to make it show up automaticlly is to write the menu right into the acad.cui (which defeats the purpose of the partial.cui in the first palce!)
Am I missing something!
Thanks,
CM
Posted by: CM | October 25, 2006 at 08:34 PM
Hi CM,
When you say it gets written into acad.cui by the ARX module, do you mean it gets loaded, or that the XML from your partial CUI is inserted into the standard acad.cui?
Please explain exactly how the CUI is being loaded (I'll see if I can see something obviously wrong - otherwise I'd suggest submitting it via one of the Customization Discussion Groups or via the ADN website, if you're a member).
Regards,
Kean
Posted by: Kean | October 25, 2006 at 09:07 PM
Hi Kean,
Thanks very much for getting back to me. As I said before, I'm always impressed with your work.
To clairify, the partial cui is 'loaded' into the Acad.cui (Please see http://www.swatchdigital.com/cui.aspx for a screen shot). I have not 'Inserted' xml/menus or toolbars into the ACAD.cui if that is what you are asking. I believe this is the intent of the partial.cui -to allow third party UI without having to resort to writing directly into the users Acad.cui. The problem is that even when the partial.cui seams to be 'loaded' into the acad.cui - it just does not show up. (See screen shot again). Thus the question? How to get menus to show up without reverting back to the old write'em in method.
By the way, I've posted this on Discussions but without any response. (Many others have the same request!)
Thanks,
cm
Posted by: CM | October 31, 2006 at 07:00 PM
Hi CM,
Thanks - I just posted an entry to address this (I hope the approach works for you).
http://through-the-interface.typepad.com/through_the_interface/2006/11/loading_a_parti.html
Regards,
Kean
Posted by: Kean | November 01, 2006 at 05:35 PM
Hi Kean
I´m using Autocad 2006, and I did everything you said in Loading modules on AutoCAD startup, but it wasnt work.
The question is, is possible to Loading modules on AutoCAD startup in Autocad 2006 ? and How ??
Regards,
Claudio
Posted by: Claudio | March 04, 2007 at 01:26 AM
Hi Claudio,
Have you tried using the Registry location for AutoCAD 2006 (probably under "R16.2" instead of "R17" - something to check using Regedit and the ObjectARX Developers Guide)?
Regards,
Kean
Posted by: Kean | March 04, 2007 at 07:01 AM
Hello Kean
I can load my dll when Autocad starup throw the registry, but i cant execute commands. For example my dll has a , i have to type "LoadTool" in the command line, but i need to execute the command when Autocad starup. I tried with the keys Command and Groups, in the Key Command I insert a string value called LoadTool = LoadTool, and in the Key Groud i did the same, string value LoadTool = LoadTool. I´m doing somethign wrong ?
Thank you Kean...
PD: I´m using Autocad 2006 and sorry for my poor english
Posted by: Claudio | March 08, 2007 at 05:34 AM
Sorry in my up post in the second line "For example my dll has a...." has a "command method called loadtool", I cuted and pasted this part of the text and it doesn´t appear then...
Posted by: Claudio | March 08, 2007 at 05:40 AM
Hi Claudio,
Sorry for the delay - I've been on the road for the last 10 days. You might be hitting a problem I mentioned in this post:
http://through-the-interface.typepad.com/through_the_interface/2006/09/initialization_.html
I'd suggest first trying to set "Copy Local" to false for acmgd.dll and acdbmgd.dll. Hopefully that will fix your problem.
Regards,
Kean
Posted by: Kean | March 15, 2007 at 12:35 PM
Hi Kean,
Just a quick thanks, exactly what I was looking for.
Thanks
Jim
Posted by: Jim | May 02, 2007 at 08:59 AM
You ROCKS!!! Excelent information!! Don't you think about write a book??
Posted by: Francisco Lomas | July 30, 2007 at 10:00 PM
Hi Francisco,
Not right now, although maybe one day I will, who knows? For now I like the format of blogging, it allows me to cover pretty much any topic without being constrained by logic. :-)
Kean
Posted by: Kean | July 31, 2007 at 08:05 AM
Hi Kean!!
I will post this to ADN too, but maybe you can help me too...
I used exactly what you tell in this post to build an installer fro my .net app hosted in AutoCAD Map 3d 2007, it works great!! but i must use 2k8, well i unsinstall my 2k7 and replace it with 2k8, then I look into the registry and noticed some versions change, ex R17 to R17.1, 5002 to 6002, i modified my installer to match the key into the registry and rebuild it, but acad 2k8 doesn't load my assembly, i reviewed the registry, everything ok, the location of the assembly was ok but if you try to use netload it doesn't load too, i try to use the netload to use my assembly in my debug folder and it loads the app, it was strange, then i modify the reg key to point to my debug folder and guess what... It doesn't work!! some ideas?? i give you my reg file, but it is ok as i see...
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R17.1\ACAD-6002:409\Applications\MDMQ_GIS]
"DESCRIPTION"="Utilidades GIS del MDMQ"
"LOADER"="C:\\Archivos de programa\\AutoCAD Map 3D 2008\\MDMQ_GIS_AUTOCAD.DLL"
"LOADCTRLS"=dword:00000002
"MANAGED"=dword:00000001
Posted by: Francisco Lomas | August 13, 2007 at 09:33 PM
Hi Francisco,
Please email me the case ID so I can check it out from this side.
By the way - which language version of Map3D are you using?
The other tools we often recommend for diagnosing these issues are RegMon and FileMon, available from http://sysinternals.com.
Regards,
Kean
Posted by: Kean | August 13, 2007 at 10:17 PM
The language is English, and I use the key created by the AutoCAD installer...
Posted by: Francisco Lomas | August 13, 2007 at 10:54 PM
An update more, whe i modify the key to an incorrect name of the dll nothing occurs with AutoCAD on load, but you can load the same assembly with netload, but if the name is correct in the registry you can't use the assembly it doesn't load!!
Posted by: Francisco Lomas | August 13, 2007 at 11:03 PM
More info, I use the tools that you recommend me and i found that the assembly is loades, it reads the registry, loads the assembly but it doesn't start the execution, maybe is some kind og log where i can search more?? the event viewer is empty of autocad or related events...
Posted by: Francisco Lomas | August 14, 2007 at 12:14 AM