AutoCAD .NET
-
This was a topic suggested by Scott Underwood (thanks, Scott! 🙂 to look at COM vs. NET and go through their respective advantages and disadvantages… This is really an interesting discussion topic, and one that I'd like people to help turn into an interesting discussion. I can certainly talk about the differences and pros/cons of the two technologies from my own memory/experience/perspective, but others will have things to say on this, I'm sure... please feel free to do so! 🙂 Rather than going into low-level detail on either COM or .NET, I'd suggest looking into their respective Wikipedia sites. Both…
-
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…
-
In my previous post I described how you could use the Autodesk.AutoCAD.Runtime.IExtensionApplication interface to implement initialization code in your .NET module. Building on this, we're now going to look at how use of the Autodesk.AutoCAD.Runtime.IExtensionApplication interface can also allow you - with very little effort - to optimize the architecture of your managed modules for faster loading into AutoCAD. First some information from the "Using .NET for AutoCAD documentation" (which is available in the ObjectARX Developer's Guide on the ObjectARX SDK): When AutoCAD loads a managed application, it queries the application's assembly for an ExtensionApplication custom attribute. If this attribute…
-
It's very common to need to execute some code as your application modules are loaded, and then to clean-up as they get unloaded or as AutoCAD terminates. Managed AutoCAD applications can do this by implementing the Autodesk.AutoCAD.Runtime.IExtensionApplication interface, which require Initialize() and Terminate() methods. During the Initialize() method, you will typically want to set system variables and perhaps call commands which execute some pre-existing initialization code for your application. Here's some code showing how to implement this interface using VB.NET: Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.EditorInput Imports System Public Class InitializationTest Implements Autodesk.AutoCAD.Runtime.IExtensionApplication Public Sub Initialize() Implements _…
-
One of the services ADN provides its members is representation of their wishes with Autodesk's Engineering teams, helping influence product direction. For instance, each year we run an API wishlist survey for a number of our products (this year it was AutoCAD, ADT, Revit, Inventor, and Map 3D). An online survey for each product gets filled out by ADN members, allowing them to provide targeted feedback that goes straight to the appropriate Product Management contacts. I wanted to talk about an item that has featured highly in recent AutoCAD API surveys – the exposure of custom objects through .NET. The…
-
Another case of planets aligning: two different people have asked me this question in two days... It's quite common for commands to require users to provide additional input during execution. This information might be passed in via a script or a (command) from LISP, or it may simply be typed manually or pasted in by the user. The fact is, though, that commands don't actually take arguments. It may seem like they do, but they don't. What they do is ask for user input using dialogs or the command-line. Here are a few tips on how to support passing of…
-
In this earlier entry I showed some techniques for calling AutoCAD commands programmatically from ObjectARX and from VB(A). Thanks to Scott Underwood for proposing that I also mention calling commands from .NET, and also to Jorge Lopez for (in a strange coincidence) pinging me via IM this evening with the C# P/Invoke declarations for ads_queueexpr() and acedPostCommand(). It felt like the planets were aligned... 🙂 Here are some ways to send commands to AutoCAD from a .NET app: SendStringToExecute from the managed document object SendCommand from the COM document object acedPostCommand via P/Invoke ads_queueexpr() via P/Invoke Here's some VB.NET code…
-
Someone asked by email how to get the block import code first shown last week and further discussed in yesterday's post working with AutoCAD 2006. I've been using AutoCAD 2007 for this, but to get it working there are only a few changes to be made. Firstly you'll need to make sure you have the correct versions of acmgd.dll and acdbmgd.dll referenced into the project (you should be able to tell from their path which version of AutoCAD they were installed with). Secondly you'll need to modify your code slightly, as WblockCloneObjects() has changed its signature from 2006 to 2007.…
-
I didn't spend as much time as would have liked talking about the code in the previous topic (it was getting late on Friday night when I posted it). Here is a breakdown of the important function calls. The first major thing we do in the code is to declare and instantiate a new Database object. This is the object that will represent our in-memory drawing (our side database). The information in this drawing will be accessible to us, but not loaded in AutoCAD's editor. Database sourceDb = new Database(false, true); Very importantly, the first argument (buildDefaultDrawing) is false. You…
-
We're going to use a "side database" - a drawing that is loaded in memory, but not into the AutoCAD editor - to import the blocks from another drawing into the one active in the editor. Here's some C# code. The inline comments describe what is being done along the way. Incidentally, the code could very easily be converted into a RealDWG application that works outside of AutoCAD (we would simply need to change the destDb from the MdiActiveDocument's Database to the HostApplicationServices' WorkingDatabase, and use a different user interface for getting/presenting strings from/to the user). using System; using Autodesk.AutoCAD;…