Showing posts with label AutoCAD Addin. Show all posts
Showing posts with label AutoCAD Addin. Show all posts

Tuesday, August 7, 2012

How to Load AutoCAD.Net Plugin Dlls automatically?

If you are developing AutoCAD.Net plugins, then to load your .Net Plugin Dll, you have to do use "NetLoad" command and specify your Plugin Dll, each time you want to load it. And in a developer's life, you have to compile/debug code lots of times and so have to issue NetLoad lots of time as well and realy it is getting annoying thing.

I searched for some solution to either automate NetLoad command e.g. see this post which is using LISP Routines to automate the NetLoad, or somehow, AutoCAD should pick it automatically when it starts, as this Plugin dll is part of AutoCAD.

Using Lisp routine method give me some problem that it was calling it 2 or 3 times and I was not able to understand why. This also involves my laziness to investigate LISP behavior (you know LISP is bit rusty procedural style language). So I rejected that because that was hanging AutoCAD on my machine. Annoyed

However, I found this very good post about Automatic loading of .NET modules (by Kean Walmsley) about using Registry to let AutoCAD load our plugin dlls. Although, initially you have to create your registry keys manually but then you can export your registry keys to .reg file and modify and update using any Text Editor. I found this method more convenient and have not faced any problem like in case of LISP routines.

Saturday, July 21, 2012

How to send AutoCAD commands via C#?

I’m working on an AutoCAD plugin in .Net (C#) and  was trying to insert Blocks from multiple DWG files into drawing area via C#.  Initially I was trying to write routines for Drag & Drop, Rotating, Scaling etc. However, AutoCAD’s built-in command “INSERT” is doing all such tasks. So I started looking for the method to Execute AutoCAD’s built-in commands.

I tried INSERT command and here is a code segment from  my C# Project initiated with AutoCAD.Net Wizards (Download from Autodesk Developer Network).

AutoCAD Command Method (C#)
  1.       [CommandMethod("InsertDWG")]
  2.         static public void SendINSERTCmd()
  3.         {
  4.             string DWG = @"D:\MYDWGs\1047.DWG";
  5.             string InsertCmd = @"_.-INSERT " + DWG + '\r' + '\n';
  6.             Document doc = Application.DocumentManager.MdiActiveDocument;
  7.             doc.SendStringToExecute(InsertCmd, true, false, false);
  8.         }

After compiling your code, use “NetLoad” to load your .net DLL and issue “InsertDWG”. You  will see the command line in AutoCAD’s command window. Drawing Block would be attached to your mouse pointer and you would be able to Drag, Drop, Scale, Rotate and all perform all functions that are provided in AutoCAD normally.