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\MyTestApplication\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\MyTestApplication\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\MyTestApplication\Commands]

"TST"="TST"

"ANOTHER"="ANOTHER"

[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\MyTestApplication\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:

  1. 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!!!

  2. My pleasure - glad you're finding the information useful. 🙂

  3. Matthieu Lefebvre Avatar
    Matthieu Lefebvre

    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).

  4. 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

  5. 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

  6. 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 (discussion.autodesk....) 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: keanw.com/....

    Regards,

    Kean

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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 swatchdigital.co... 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

  12. Hi CM,

    Thanks - I just posted an entry to address this (I hope the approach works for you).

    keanw.com/...

    Regards,

    Kean

  13. 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

  14. 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

  15. Hello Kean

    I can load my dll when Autocad starup throw the registry, but i cant execute commands. For example my dll has a <commandmethod("loadtool")>, 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

  16. 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...

  17. 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:

    keanw.com/...

    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

  18. Hi Kean,

    Just a quick thanks, exactly what I was looking for.

    Thanks
    Jim

  19. Francisco Lomas Avatar
    Francisco Lomas

    You ROCKS!!! Excelent information!! Don't you think about write a book??

  20. 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

  21. Francisco Lomas Avatar

    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

  22. 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 sysinternals.com.

    Regards,

    Kean

  23. Francisco Lomas Avatar

    The language is English, and I use the key created by the AutoCAD installer...

  24. Francisco Lomas Avatar

    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!!

  25. Francisco Lomas Avatar

    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...

  26. Hi Kean,

    great site, thanks! I just wanted to share that I found out by trial and error that you can not modify the registry BOTH in "HKEY_CURRENT_USER..." and "HKEY_LOCAL_MACHINE..." in the way you describe. Doing so, it's not only that the dll ist not loaded at startup, you also can not load the dll using the netload command any more. I am not sure if this is a bug or wanted. Can you comment?

    Regards, Christian

  27. Hi Christian,

    I don't believe I said to put it in both places - I meant to suggest using one or the other:

    "Essentially the information can be stored in one of two places: under HKEY_LOCAL_MACHINE or under HKEY_CURRENT_USER."

    I don't believe the module should be stopped from loading if it's in both places, however. It's not something I've looked into, myself.

    Regards,

    Kean

  28. Hi kean

    I Wanted to know if the above method is only for automatic loading of dlls and not automatic execution of command within the dll.

    i Tried the above method and found thatwe need to type the command at the command prompt to execute the command.Can i know how to load a dll and execute the command automatically in presnt in the dll.

    Thanks
    Sony

  29. Hi Sony,

    This is all about loading: if you need to launch a command automatically, you should check out these posts:

    Calling AutoCAD commands from .NET
    Techniques for calling AutoCAD commands programmatically

    If you attempt to launch a command on Initialize(), be warned: if the module is demand-loaded on startup then the editor may not be ready to have a command launched.

    Regards,

    Kean

  30. Hi Kean,

    Thanks for replay on demand loading.

    i still had a doubt,calling command through .net is fine , but i want to execute the command on autocad startup.i.e: when i open autocad i want to execute my command, the command in turn will load a custom menu in autocad.

    i hope i am clear with my question.

    Thanks kean

  31. Use the Registry to have your module loaded on AutoCAD startup, and then as the module loads (in the Initialize function - see this post) you can call something to queue up the command - probably ads_queueexpr() (see this post).

    Kean

  32. Is there a way to auto unload a dll after it has been loaded and the command issued? For example, the dll is already loaded, the user has issued a command which opens a form. When the user closes the form the dll is automatically unloaded. I ask this because the question came up when we need to release a new dll version to users, some users don't close their AutoCAD at the end of the day, and in testing, the dll cannot be copied over to the client if it is 'in use'.

    Thanks

  33. Sorry, James - there's currently no NETUNLOAD ability in AutoCAD.

    Kean

  34. Hi,

    I found that AutoCAD 2009 couldn't load my managed library if the "LOADER" string value in the registry contained "\\", so please use "\" in the path to your dll.

    Regards,

    Alin

  35. Can We load ARX File in the same way through .net

  36. Sony -

    Yes. Exactly the same mechanism works for .arx files (you just need to drop the MANAGED key or set it to 0).

    Kean

  37. Thank you Dude

  38. Brian Stafford Avatar

    Hi Kean,

    Concerning "loading modules on command invocation", is it possible to use this technique on methods tagged with the "LispFunction" attribute?

    Regards,

    Brian

  39. No - you will need to force load on startup.

    Kean

  40. Kean,

    Great resource! I am upgrading a bunch of our code I wrote for 200-2004 products with lisp, and VBA - some VB6 sprinkled in there - this forum has really helped - I appreciate your time.

    As for the autoloading - I set up a test project - worked great, so I know I'm doing it right.

    However - When I attempt to load my full dll (that references other custom DLL's I've created) - It does not load. I have a feeling its due to the custom dll's I've referenced to my project (these are libraries that contain typical functions I use - string conversion methods, a "findfile" function like that in lisp, etc). Could you shed some light on why I might not be getting my functions to load on startup? (they load fiune manually with netload). I'm using VB.net '05

  41. Eolson,

    I typically use the Process Monitor (the successor to Regmon and Filemon) to diagnose these problems: you can see what Registry keys were accessed and files loaded.

    I'd also suggest placing your assemblies inside the AutoCAD program folder, to see if that changes anything (with the Registry paths modified appropriately, of course).

    Kean

  42. I have a VB.net dll. It works fine if I netload the dll on a 64 bit machine. What I'm having trouble with is how to get AutoCAD a 64 bit machine to recognize the registry entries. My installation package puts the entries under a Wow6432node key (which I believe is normal), but AutoCAD is not able to find them.

    On a 32 bit machine, AutoCAD finds the registry entries I've made just fine, but if I install on a 64 bit box, AutoCAD doesn't find them. I'm trying to figure out what I have to do to resolve this.

    I would appreciate any input you might have.

    Thanks,
    Chuck

  43. Hi Chuck,

    Sorry - I currently don't have a 64-bit OS installed. I suggest submitting your question via ADN (if you're a member) or otherwise trying the AutoCAD .NET (or ObjectARX) discussion groups.

    Regards,

    Kean

  44. Magnus Jørgensen Avatar
    Magnus Jørgensen

    Hi...

    I have been using this feature for some time. But i've just noticed that my dll is loaded at command invocation, despite having set LOADCTRLS = 2...

    Very strange. And i seem to remember that it worked once. What could have gone wrong?

  45. Hi Magnus,

    It's hard for me to say - it should be working. Perhaps AutoCAD's using a different set of Registry keys than you think it is? You might try using RegMon (or ProcessMons) from Microsoft's SysInternals site to see what's being used...

    Regards,

    Kean

  46. Cadbloke.wordpress.com Avatar
    Cadbloke.wordpress.com

    Another way to approach this is to add a line to your acad2010doc.lsp as per the forum post at forums.augi.com/archive/index.php/t-48924.html (which links to this post).

    I prefer this method because I find it easier to tweak when I'm debugging or updating. It also works if you don't have regedit access.

    It is not as elegant as on-demand loading so don't go nuts with multimegabyte dll's.

    cheers
    Ewen

  47. Christian Geisser Avatar
    Christian Geisser

    Hello,

    it's always hard for me to remember where I put the piece of paper where I wrote down the values for the LOADCTRLS registry key to load managed assemblies.

    But today I found the ApplicationLoadReasons enumerator located inside acdbmgd.dll.

    Here you can find the LOADCTRLS values:
    Autodesk.AutoCAD.DatabaseServices.ApplicationLoadReasons

    Another thing I just came across (Windows 7 x86, DE):

    I created a new registry key to automatically load my assembly while debugging, but none of my command methods has been recognized from Autocad. Loading my assembly using the 'netload' commmand always worked fine...

    It seems that there is some kind of a localization issue when Autocad is retrieving the LOADER value from the registry.

    I'm working with a German version of Windows 7 and an Englisch version of Autocad Architecture 2010.

    Usually I open the file properties of my assebmly to copy and paste the path to the LOADER key in the registry editor.

    This is the directory information displayed by the file properties:
    "C:\Users\..."

    But when I use the Explorer to navigate to the location of my assemby, the localized folder name "C:\Benutzer" is used instead of "C:\Users":

    "C:\Benutzer\..."

    Only when I change the folder name of the LOADER registry key from "Users" to the localized name "Benutzer" my commands are recognized by Autocad.

    If this has already been resolved this means I'm not up to date with my Autocad version.

    Regards Christian

  48. Hello Christian,

    Yes, I used to use rxdlinkr.h from the ObjectARX SDK to find the values, although these days I remember I need either 2 or 12 (and look at the application information in the Registry to remember which I need to use).

    The issue you've described sounds peculiar, and I'd like someone from my team to take a look. Please go ahead and submit it via the ADN site, and we'll look into it.

    Thanks & regards,

    Kean

  49. Christian Geisser Avatar

    Hi Kean,

    I'm glad to tell you that I'm not able to reproduce my "I came across..."-issue anymore. I've no clue what went wrong when I've created the registry key that day but now I can change all parts of the path, no matter if localized values or not, and demand loading is always working fine.

    I think I was a little bit too fast with my report. Maybe rebooting solved the problem.

    Thanks for your reply!

    Regards
    Christian

  50. I am trying to use demand loading with AutoCAD 2010. There seems to be some small difference in the requirements of 2010 and 2007 demand loading, however, and AutoCAD 2010 does not recognize the command. I am loading the registry entries into the AutoCAD 2010 registry subkey: HKEY_LOCAL_MACHINE/SOFTWARE/Autodesk/AutoCAD/R18.0/ACAD-8005:409/MyApp. When I call the function in AutoCAD, it says that it does not recognize the command.

  51. Kean Walmsley Avatar

    Nothing fundamental has changed between 2007 and 2010, just the product key.

    If your app loads manually using NETLOAD, then I suggest posting more details either to the AutoCAD .NET Discussion Group or to ADN, if you're a member.

    Kean

  52. Thank you. I figured out it was in the project itself. Copy Local must be set to False for acdbmgd and acmgd dlls.

  53. Hi Kean, I have a regedit which works with AutoCAD2010, but when I try to register it to the 2011version, I get a fatal error. Is there something that should be different between 2010 and 2011 that I am looking over? Thanks for your help

  54. Kean Walmsley Avatar

    Hi Andrew,

    The Registry key AutoCAD looks under has changed from R18.0 to R18.1. Otherwise everything is the same, and should work similarly.

    Regards,

    Kean

  55. Hi Kean.
    Congratulation for your post. It's clear and very understandable.
    I've try your method, and it work perfectly.
    I would like to know if you know how all this take place in case of extend AutoCAD software.
    I'm talking about :
    - AutoCAD Mechanical
    - AutoCAD Civil 3D
    - AutoCAD Electrical

    Because, if all those separate soft has near the same interface and structure, their key register structure is not the same. So i've difficulty to made the same techniques you provide for AutoCAD with AutoCAD mechanical (and other i imagine).

    Do you know something about autoload of .Net modules with those derivated software ?

    Thanks for your support.
    Regards,

    Rémy D-F

  56. Kean Walmsley Avatar

    Hi Rémy,

    Yes - the specific Registry key will vary between products. The "safe" way to do this is via runtime code that generates the keys in the appropriate location for the product within which the DLL has been NETLOADed. See this post for some code to do this.

    Best regards,

    Kean

  57. Ok, i'll see what i can do.
    Thank you very much for your quick and efficient response.

    Regards,

    Rémy D-F

  58. Hi , I wrote a progam and made a DLL (C:\program\Layer.dll) , Foloow the steps its doesnt load when CAD Start, i using win 7 , Any idea please

  59. Kean Walmsley Avatar

    I have no idea what's wrong. You may want to try using the ProcessMonitor tool (the successor to RegMon) from Microsoft to find out which Registry accesses have been made.

    Otherwise I suggestion posting your Registry export to the relevant discussion forum.

    Kean

  60. Hi Kean, Many thanks for your reply. I check my Windows Registry Editor Version 6.1, It would be any change on it?

  61. Kean Walmsley Avatar

    The version of your Registry editor isn't relevant. It's the contents of the Registry key described in this post that's important.

    Kean

  62. Great blog, I reference it constantly... Keep it up, hope your day job pays well so the rest of us benefit from you generosity.

    However... Any thoughts on setting these registries outside of user interaction? To clarify, we are deploying 2010 and I have my dlls ready to go and a .reg file for autoloading, but so far I've only been able to run the reg file manually, physically from the installed system. I'd like to set something up so it happens on install or first run of the software.

    Thanks for everything.

  63. Hi Chris,

    You can either create them when your modules load (see our Plugins of the Month for examples of this) or from an installer outside AutoCAD.

    I hope this helps,

    Kean

  64. Hi Kean,
    I am having an issue demand-loading .dll's in autocad mechanical 2008. I am able to netload the .dll's from within autocad, as well as autoload them from a registry file (loadreason 2), but the success stops there. Our project has around 10 .dll's that we use on top of autocad, so we would much prefer to demand load them when needed as opposed to autoloading them all at the start. Any advice as to why the demand load function would not be working?

    Also, is there a way to demand load .dll's from within a profile as opposed to the general Autocad settings? Our other specifications are loaded within a profile we generate for the user.

    Thanks for your time,
    Carol

  65. Hi Carol,

    In the past I've used RegMon and FileMon (and more recently Process Monitor) to check what registry/file system acceses are made by AutoCAD: they will often show where the issue is.

    As for your other questions, please post them to the ADN team, if you're a member, or otherwise the AutoCAD .NET Discussion Group.

    Kean

  66. Kean,

    I have created a Ribbon bar with VB.NET. I have tested it and it works when I load it with the NETLOAD command. I want to automatically load it when AutoCAD starts. I tried NETLOADing it in ACAD.LSP, but that didn't work. I modified the registry as shown below and it still doesn't show the new ribbon bar. Plus, after modifying the registry it will not display even after using the NETLOAD command unless I remove the registry entry. Can you help?

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R18.1\ACAD-9005:409\Applications\ChaseDoorsRibbon]

    "Description"="Chase Doors Ribbon"

    "LOADCTRLS"=dword:0000002

    "MANAGED"=dword:00000001

    "LOADER"="C:\\Documents and Settings\\mconley\\Desktop\\New ColdGuard Design Automation\\ChaseDoorsRibbon\\bin\\Debug\\ChaseDoorsRibbon.dll"

  67. Mike,

    I can't tell what the issue is from your .reg file. I tend to use Process Monitor (the successor to RegMon and FileMon) to diagnose these issues: you can quickly see when AutoCAD loads whether it's accessing this section of the Registry and whether it's trying to load your DLL from the file system.

    Failing that you might try the ADN team, if you're a member, or otherwise the AutoCAD .NET Discussion Group.

    Kean

  68. Hallo Kean,

    I'm using AutoCAD Civil 3D 2010
    under Windows 7. I've used Regedit
    to add my DLL to the registry under the following Directory:
    "HKEY_LOCAL_MASCHINE\SOFTWARE\Autodesk\AutoCAD\R18.0\Applications\MyApp"

    It doesn't work, but with netload.
    Seems like AutoCAD doesn't find the entry.

    Under the Directory
    "HKEY_LOCAL_MASCHINE\SOFTWARE\Autodesk\AutoCAD\R18.0\" there is only one subfolder called "AdImaging"

    Where Do I have to put my Application Entry?

    Thanks, Max

  69. Hi Max,

    I suggest using Process Monitor to see what Registry keys acad.exe is looking for and not finding.

    This is how I tend to diagnose such situations.

    Regards,

    Kean

  70. Hi Kean,

    thanks for your advice. Process Monitor shows, that mydll.dll was loaded successfully for a few times.
    But some entries in Process Monitor show the result "BUFFER OVERFLOW" and "FILE LOCKED WITH ONLY READERS".

    acad.exe seems to look for an mydll.ini and says "NO SUCH FILE", because I don't have one.

    "ACPUBLISHDEMANDLOADINGMODULE" causes "NAME NOT FOUND"

    Do have any ideas how I can solve that problem?

    Thanks, Max

  71. Hi Max,

    A lot of the "error" messages can be ignored (and I can't recall whether that's the case for these specific ones, unfortunately).

    I use Process Monitor (or RegMon, one of its ancestors) to check Registry accesses, when it comes to diagnosing demand-loading. There are other tools (such as Dependency Walker) which helps with DLL-related issues.

    Beyond this I'm afraid I can't give you any specific advice: please post your follow-on questions to the ADN team, if you're a member, or otherwise the AutoCAD .NET Discussion Group.

    Regards,

    Kean

  72. What is the new registry key for R18.1?

  73. I'm afraid I don't understand the question.

    If you're asking what the new R18.1 Registry key is for, it's for AutoCAD 2011. But I suspect you mean something different.

    Kean

  74. Correct. The registry key in R18.0 is "Applications" and thats works for me for Autocad 2010. What is the name of the registry key in R18.1 for autoloading .NET apps. I've tring putting the entries in "AutodeskApps", but have not had any luck getting apps to autoload. I apologize for being obtuse and not providing enough context in my question for you to answer succinctly. You said "The Registry key AutoCAD looks under has changed from R18.0 to R18.1", and I was hoping pass on the name of the reistry key that Autocad 2011 uses to autoload applications.

    Thank you for all your wonderful help.

  75. Aha, now I see.

    Actually it has exactly the same name: the Applications key may not exist in your user profile, but if not, just create it.

    Kean

  76. Hi Kean,
    Is it possible that LOADER can be an "expandable string value" (REG_EXPAND_SZ) instead of just a "string value" (REG_SZ) type? I would like to take advantage of system variables for paths and such.

  77. Hi Buddy,

    Apparently so: I didn't even know the REG_EXPAND_SZ type existed (not sure which hole my head was down, but anyway 🙂 but I just gave it a try renaming my previous LOADER setting to something else and creating a new REG_EXPAND_SZ LOADER setting of "%ProgramFiles%\Autodesk\...\MyApp.dll" and it worked very well.

    That's cool!

    Kean

  78. It appears that you can use REG_EXPAND_SZ for versions 2010 and above. I tried this on 2007, 2009 and it didn't work but applied it to 2010 and it worked fine.

  79. Thanks, Buddy - I should have added the caveat I was testing with AutoCAD 2011.

    Kean

  80. Hello Kean

    you wrote:

    [HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\MyTestApplication]
    "DESCRIPTION"="Kean's test application"
    ....
    "LOADER"="C:\\My Path\\MyTestApp.dll"

    [HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\MyTestApp\Commands]
    ....

    The first line uses "MyTestApplication", the second one "MyTestApp". Why? Does the second line relates to the name of the file "MyTestApp.dll"? Or should it also be "MyTestApplication"?

    Regards

    Peter

  81. Hello Peter,

    Wow. Nearly 5 years on - in one of this blog's most popular posts - and it's the first time anyone's raised that. You're right - it should be MyTestApplication.

    Thanks for pointing it out,

    Kean

  82. Hello Kean

    yepp - 5 years (and 20 printed pages) are a long time - but you needed only 5 min to reply 😉

    BTW: There was also a discussion about the values of LOADCCTRLS and the sources inside ADN. How to learn these values as non-ADN-member?

    Peter

  83. If you download the ObjectARX SDK and look at the Developer's Guide (arxdev.chm) in the Docs folder, you should see it documented (search for "Demand Loading for .NET Applications").

    Kean

  84. Hi Kean,

    Your article is very informative and useful.

    I have tried the method you suggested in this post, and also faced the same issue as Claudio.

    Have used ProcessExplorer and verified that my DLL has been loaded. But tried typing in the command name to invoke it, but AutoCAD displayed unknown command.

    I have checked that my DLL app is built with Copy Local = False for all my AutoCAD reference dlls.

    No issue for me when I manually netload my app DLL.
    No issue also when I launch AutoCAD using Visual Studio Debug mode.

    I am using AutoCAD Arch 2011, and have edited the Regisry at
    [HKEY_CURRENT_USER\Software\Autodesk\R18.1\ACAD-9004:409\Applications\Test]
    "DESCRIPTION"="AutoNetloadDLL"
    "LOADCTRLS"=dword:00000002
    "MANAGED"=dword:00000001
    "LOADER"="C:\\MyApp\\bin\\Release\\MyApp.dll"

    Any ideas what is causing the unknown command?

  85. Two possibilities come to mind:

    * You have an exception being thrown in your Initialize() method (if you're implementing IExtensionApplication). AutoCAD will catch the exception and reject the DLL load.

    * Your command class or the command methods are not declared as public. This is a subtle issue that sometimes takes me a long time to notice.

    It could be for other reasons, of course. If the commands work fine when the DLL is NETLOADed, then it's unlikely the second is an issus, of course. And as I've just re-read your comment, and see it works fine on NETLOAD, that means it's something else.

    I see you're loading on Startup: you may have initialization code (adding to the ribbon, or perhaps relying on the ActiveDocument), which is failing and throwing an exception when loaded on startup vs. on command invocation or via NETLOAD (which both generally happen after AutoCAD has everything instanciated and set up - which is not the case if loaded on startup).

    I hope this helps,

    Kean

  86. I managed to solve my problem. It's to do with my dll reading the app.config file which confuses with the acad.exe.config file settings. Hence my intended settings were not loaded, and causing the commands to not be recognized.

  87. Luigi Ballotta Avatar

    Thank-you Kean for this topic, truly very useful.

    Luigi

  88. Luigi Ballotta Avatar

    Hi Kean, with the goal of producing a complete installation package, the tasks I want to do are:

    1. Create myAcad.dll application [OK];
    2. Create a partial myCUI.cui file which holds my custom commands to call myAcad.dll [OK];
    3. Create a SetUp package which installs these components somewhere on customer machine [OK];
    4. Demand-loading of myAcad.dll [OK];
    5. Automatic load at any next AutoCAD startup of myCUI.cui file [!!SORROW!!].

    No matters up to step 4: the installer put the needed files on the desired paths and modify the registry to achieve the demand-loading task.

    I have no idea on how to perform the step 5: once the installer has put the myCUI.cui file in the desired installation path, how it can tell to AutoCAD to automatically load myCUI.cui at every next startup?

  89. Hi Luigi,

    Does this help?

    keanw.com/2006/11/loading_a_parti.html

    Regards,

    Kean

  90. Luigi Ballotta Avatar

    Yes, already viewed, but I had no idea how to apply it.

    So I could create a myConsoleApp application, launched from setup package. Then myConsoleApp application will launch AutoCAD and execute the snippet you suggest.

    Ultimately, to obtain my goal, the setup package will contain:

    1. myAcad.dll;
    2. myCUI.cui;
    3. myConsoleApp.

    The steps that will be taken are:

    1. [Installer] Put the files in the desired paths;
    2. [Installer] Modify the registry keys;
    3. [Installer] Launch myConsoleApp which will launch in turn AutoCAD and load the myCUi.cui;
    4. Done.

    This can be an acceptable procedure? Also from a 'professional' point of view?

    Thank-you very much for the useful informations Kean.

    Regards

  91. It's all possible... you could have a DLL that is loaded automatically on application startup inside AutoCAD that executes the code to load your partial CUI.

    You should take a look at the source code for ScriptPro 2.0 application on Autodesk Labs (a Plugin of the Month - look at the back catalog to find it), as that shows good practise for driving AutoCAD from an external app.

    You'll save a lot of effort when you can use the Autoloader in later versions, but still - it's all possible.

    Regards,

    Kean

  92. Luigi Ballotta Avatar

    Exactly: have a dll that is loaded automatically on AutoCAD startup. This is my goal! The one you have suggested i think, but what I did not understand is how load automatically this dll from my setup package? How setup package can tell to AutoCAD "load this.dll"?
    Driving AutoCAD externally from a console application is not very nice to me.
    I'm trying to individuate the best procedure to do so, yes I think the one I have outlined is not the best.
    The Autoloader you suggested is very great but if i had to install my application on AutoCAD versions earlier than 2013, it doesn't work.
    Thanks & regards.

    Luigi

  93. I apologize, I have explained myself badly.

    Once the dll is loaded, I had to launch the command that call that dll, Here is the matter: to tell AutoCAD that command in order to run that dll.

    Thank-you for the patience...

    Luigi

  94. Not a problem - I could also have been more explicit in my replies.

    You can have code execute on load of a module using this approach:

    keanw.com/2006/09/initialization_.html
    keanw.com/2006/09/optimizing_the_.html

    Be careful, though: if running code on AutoCAD startup, it may be too soon to run certain commands. This approach may help:

    keanw.com/2013/01/displaying-a-dialog-on-autocad-startup-using-net.html

    Regards,

    Kean

  95. Luigi Ballotta Avatar

    Hi Kean, I want to thank you for having shown the way to go. Very, very helpful tips.

    So...what else? If you were not there, someone have to invent you... (not very sure about my English)

    Thanks & Regards

    Luigi

  96. Hi Luigi,

    Your English is very clear - thanks for the kind words.

    I think it's probably fair to say that if I didn't do this then someone else would (nature abhors a vacuum ;-). Although, in fairness, between the ADN DevBlog, the Autodesk Discussion Groups and The Swamp, I'd hope people now have better access to the information they need than they did when I started the blog.

    Regards,

    Kean

  97. Silke Förnzler Avatar
    Silke Förnzler

    Hello Kean,

    I'm having a wish here and I kind of hope to get you a bit curious about it...:
    Additionally to the demand loading I have realized for my managed Autocad dlls so far (OnCommandInvocation using the Autoloader, which is quite cool!), I'd like something similar to 'LoadOnProxyDetection' (which is only for custom object / dbx), but for my Overrules (they all have xdata attached)!
    I have already asked this via adn, but unfortunately they had no creative suggestions, just told that something like this doesn't exist yet and that the way to go is 'LoadOnStartUp'...
    What do you think? Any ideas? Worth a post maybe? 🙂

    Will be glad about any comment from you,
    regards,
    Silke

  98. Kean Walmsley Avatar

    Hello Silke,

    Nice to hear from you. 🙂

    The only creative suggestion I might have is to add a dummy (could be non-graphical, stored in the NOD) custom object inside drawings you know use your overrule. This could then be used to force the load of your .DBX when needed (on proxy detection). I don't think it could be made to work for .NET DLLs (you need C++ to define your object, anyway), but hopefully you're still working in ObjectARX.

    Does this help, at all?

    Kean

  99. Silke Förnzler Avatar
    Silke Förnzler

    Hello Kean,

    unfortunately it's exactly like this, that the project where I use the overrules, is in .net and not ObjectArx...
    But I like your idea anyway. I might need to complicate it a bit further to meet my needs like this:
    Create a new (helper-) dbx-project. The only things that it does is, A) add the dummy custom object that you described above, as soon as one of my overruled objects is added and B) load my .net-dll in its initApp()-method. Then the only thing left would be to register the dbx for 'LoadOnProxyDetection'... Right?

    So thanks a lot for your input, this is surely better than the idea I had in mind (something about analysing a drawing when it's opened, by the help of an additional project that would have to be loaded on startup...)!

    Silke

  100. Kean Walmsley Avatar

    Hi Silke,

    That sounds about right. It may be tricky to force the load from the .DBX (you'll see and hopefully let me know :-), but it seems a reasonable approach.

    Cheers,

    Kean

  101. Silke Förnzler Avatar
    Silke Förnzler

    Hello Kean,

    well, for the time being, we've decided to settle with 'LoadOnStartup'...
    But as soon as I try to implement this idea, I'll let you know about it.

    Regards,
    Silke

  102. Hi Kean is it possible to load the tool pallete dll in autocad using demand load so that the tool pallete will automatically load when auto cad is started?

    Thanks

  103. Absolutely. You should set up demand-loading of your app so that it loads when the command displaying the palette is called.

    And if you name your command appropriately (to have the name as the palette), then the command will even be launched automatically when AutoCAD restarts if the palette was displayed the last time AutoCAD was closed.

    Kean

  104. Hello Kean,
    I like your approach to automatically loading my "in-house" application via adding registry values

    is it possible to Automatically load my VBA Application *.dvb files
    (I couldn’t find the matching Managed value)

    Best regards,
    David.

  105. Hi David,

    No - this mechanism is for ObjectARX and .NET modules. VBA and LISP modules can be loaded via the Startup Suite or using acad.lsp.

    Regards,

    Kean

  106. Hi Kean

    I have a question regarding tool palettes..
    If I drag and drop one object from drawing to tool palette
    and change its properties then would it be possible to reflect the same change in the custom menu of autocad?

  107. Hi sakbhat,

    This is off-topic (and neither is my blog a forum for support).

    Please post to the appropriate online discussion forum.

    Kean

  108. thanx...for the info

  109. Anyone did this at version 2014?

    1. Lots of people have (me included). I assume this means it isn't working for you...

      Kean

  110. And there is my solution:
    drive.google.com/a/...

  111. Gabriel Potestades Avatar
    Gabriel Potestades

    Hi Kean,

    Is this applicable for AutoCAD 2015? I have followed the instruction but it doesn't seem to work. uploads.disquscdn.c...

    1. It is still applicable... although you may want to consider using the Autoloader, instead.

      Kean

      1. Gabriel Potestades Avatar
        Gabriel Potestades

        I got it to worked that's why I deleted my comment, Sorry about that. I inserted it in the current user on Regedit but the Load or Do Not Load always prompts, how do I remove the prompt?

        This is the first time I heard of the Autoloader, is there a guide in a forum to use this?

        Regards

        1. Search on SECURELOAD: it's important you understand about application security in AutoCAD.

          There should be a number of places documenting the use of the Autoloader (particularly with respect to Autodesk Exchange Apps).

          If you can't find any, please post to the discussion groups (I simply don't have time to provide general support).

          Kean

          1. Gabriel Potestades Avatar
            Gabriel Potestades

            Thank you very much!

  112. Gnarly Gorilla Avatar
    Gnarly Gorilla

    You will need to create an executable file particularly if you have more than one CAD machine in your care. In my case I have 12 machines. So everytime I update AutoCAD, the automated loading of .NET commands has to be reintroduced into the correct areas of the registry. Then I put the file out on the network and send a group email to have everyone run the install (.EXE) file. This is also handy if you need to complete a total reinstall of AutoCAD on a users machine...to further it's craftiness....you can add in parameters in the exe file to include Express Tools, VBA Enabler, and other updates such as in the case of AutoCAD Electrical; block symbol library updates from Vendors such as Rockwell or Schneider Electric; autoloading of lsp files, or any other customizations you run department wide.

    Of course, the quickest method to create this .exe file, is by typeing "iexpress" at the windows command prompt. You may then select the files you wish to automate installations of and select any simple script files you have created to change the registry entries.

Leave a Reply

Your email address will not be published. Required fields are marked *