NET-RELOAD Utility
I’m sure many of you are aware that there is no "NETUNLOAD" command for unloading a .NET assembly from AutoCAD. Apparently this would require a significant change to AutoCAD's .NET API and is not likely to change anytime soon. Refer here for further details: http://through-the-interface.typepad.com/through_the_interface/2008/09/tired-of-not-be.html
As an alternative, I have created an AutoCAD utility that allows you to "re-load" an assembly after making modifications to your code - the best bit being you can do this WITHOUT having to re-start AutoCAD each time.
I’d be really interested in hearing if you find this utility useful for AutoCAD .NET development purposes.
Cheers,
Art
Instructions
To run the utility:
1. download the attached NetReload.dll.
2. run AutoCAD, but do NOT start it from Visual Studio.
3. NETLOAD the NetReload.dll into AutoCAD.
4. open Visual Studio and make sure a file from the particular project you wish to re-load is active.
5. go back to AutoCAD and run the NRL command.
6. in the command-line, select the Visual Studio instance you wish to re-load into AutoCAD.
If you subsequently go back to Visual Studio and change your code, and then re-run the NRL command in AutoCAD again, the code changes will automatically be loaded into AutoCAD and ready to use.
Note that you won’t be able to debug your code in Visual Studio with this tool (i.e. place breakpoints and step through code). You’ll have to re-start AutoCAD from within Visual Studio to do this.
Notes
1. Supports multiple opened instances of Visual Studio.
2. Has been checked in AutoCAD 2011 and 2012 (should also work in AutoCAD 2010).
3. Has been checked with Visual Studio 2010 (should also work for previous versions).
4. The NRL command will default to the last chosen solution for the current AutoCAD session.
5. The NRL command will advise if:
- no Visual Studio instances are currently open.
- no solutions are open in any of the currently opened Visual Studio instances.
- no document is active for the chosen solution.
How It Works
Technically the NRL command does not actually re-load the assembly for the chosen Visual Studio solution. Instead it does the following:
1. accesses the chosen Visual Studio instance using Automation (i.e. COM).
2. based on the active Document for the Visual Studio instance, gets the project to compile.
3. sets the project’s "AssemblyName" property to a random name.
4. compiles the project to an assembly in the following project folder: "\bin\Debug\ReNetload"
5. sets the project’s " AssemblyName" property back to its orignal name.
6. NETLOADs the assembly from "\bin\Debug\ReNetload" into AutoCAD.
The reason this works is because when you NETLOAD the randomly named assembly into AutoCAD, all of the previously defined commands of the same name are overriden by those defined in the last loaded assembly.
Tips
A quick way to get this assembly to automatically load when AutoCAD starts is to add the lisp code below to the acad2010.lsp / acad2011.lsp / acad2012.lsp file. Obviously you will need to change this depending on where you place NetReload.dll.
(setq S::STARTUP (append S::STARTUP (list (command "netload" "C:\\MyAutoCAD\\ NetReload.dll") (princ))))
Source Code
I have attached the C# source code file so you can build this yourself.
Note that you will need to add the following project references so that it compiles:
1. envdte.dll (Visual Studio Automation - i.e. COM).
2. System.Windows.Forms.dll (WaitCursor helper class).
3. acdbmgd.dll and acmgd.dll (AutoCAD).
Hey guys,
I made a Visual Studio 2019 solution for NETRELOAD to hopefully make compiling a bit easier.
Sadly Autodesk doesn't let me upload a single *.dll file, so if you don't want to compile:
1) Unzip the archive and navigate to NETRELOAD\bin\Debug
2) In that folder is NETRELOAD.dll
3) In AutoCAD, you can use NETLOAD to load in that file.
Tested with Visual Studio 2019 and AutoCAD Electrical 2021
hope it helps.
It is a open allow you can see detail command and lispfunction to execute do not need restart autocad.
https://github.com/chuongmep/CadAddinManager
Chuong Ho