AutoCAD .NET

  • A discussion in the comments on this previous entry seemed worthy of turning into a post. The problem appears to be that when you load a partial CUI file into AutoCAD, by default the various resources (pull-down menus, toolbars) are not displayed. This snippet of code shows you how to both load a CUI file into AutoCAD and then loop through the toolbars in your menu-group, making them all visible. You could extend it fairly easily to add the pull-down menus contained in the CUI by using mg.Menus.InsertMenuInMenuBar(). I'm choosing to leave that as an exercise for the reader mainly…

  • Thanks to Viru Aithal from the DevTech team in India team for this idea (he reminded me of this technique in a recent ADN support request he handled). A quick disclaimer: the technique shown in this entry could really confuse your users, if implemented with inadequate care. Please use it for good, not evil. I talked at some length in previous posts about MDI in AutoCAD, and how various commands lock documents when they need to work on them. When commands try to lock (or unlock) a document, an event gets fired. You can respond to this event in your…

  • Thanks to Fernando Malard for suggesting part of this topic in response to an issue he submitted through ADN support. Windows applications that make use of the .NET Framework can be configured via a ".config" XML file found in their executable's main directory (for more specifics, please see this MSDN article). In AutoCAD's case, this file is called acad.exe.config, and is found in c:\Program Files\AutoCAD 2007 (for instance). The default contents of this file for AutoCAD 2007 are: <configuration>   <startup> <!--We always use the latest version of the framework installed on the computer. If you are having problems then…

  • A colleague of mine in one of our Engineering teams just shared this tip that I'm in turn sharing with you... I was implementing an override of the abstract class Autodesk.AutoCAD.DatabaseServices.DwgFiler, which has about 40 abstract functions that have to be overridden.  Since there are no header files in C#, I couldn't just cut and paste all the signatures as a template, like I would in C++.  As I was manually typing in each signature, I noticed that Intellisense was keeping track of which signatures I had already accounted for.  I thought… if it can do that, why can't it…

  • This entry completes the series of posts about per-document data. Here are the previous entries: Some background to AutoCAD's MDI implementation and per-document dataPer-document data in ObjectARXPer-document data in AutoCAD .NET applications - Part 1 Document.UserData Now let's take a look at a second technique in .NET for storing transient (non-persisted) data with an AutoCAD document, the UserData property. The managed framework for AutoCAD associates a hash table with each document, which can be accessed using the UserData property. Hash tables are a great way to store and access data quickly: each object you store in a hash table is…

  • The last few posts have focused on the history of MDI in AutoCAD and how to store per-document data in ObjectARX applications.  Now let's take a look at what can be done for AutoCAD .NET applications... There are two main approaches for storing per-document data in managed applications loaded into AutoCAD – I'll take a look at the first in this entry and tackle the second technique next time. Define commands as instance members of a class In managed applications you can declare instance or static methods. Static methods are those specified as "static" in C# or "Shared" in VB.NET.…

  • Most of the functions to access objects in the AutoCAD drawing return generic objects/entities. The base type for objects stored in the AutoCAD database is "DBObject" – which can be used to access common persistence information such as the handle, etc. – but there is no such thing as a pure DBObject: all DBObjects actually belong to a type that is derived from this base (whether that's a "Line", "Circle", "BlockReference", etc.). The next level up in the hierarchy is "Entity", from where you can access graphical properties such as color, layer, linetype, material, etc. The sample code in this…

  • This post takes the sample code shown in the last entry, converts it to VB.NET and adds in some code to access specific entity properties rather than simply calling list(). I won't step through the code this time, but here's the section of code that gets and dumps out the various entity properties: Dim ent As Entity = CType(tr.GetObject(objId, OpenMode.ForRead), Entity) ' This time access the properties directly ed.WriteMessage(vbLf + "Type:         " + ent.GetType().ToString) ed.WriteMessage(vbLf + "  Handle:     " + ent.Handle().ToString) ed.WriteMessage(vbLf + "  Layer:      " + ent.Layer().ToString) ed.WriteMessage(vbLf + "  Linetype:   " + ent.Linetype().ToString) ed.WriteMessage(vbLf…

  • Many AutoCAD commands that work on sets of entities support two styles of working: verb-noun or noun-verb. This basically means that if the user has pre-selected a set of entities (the "noun") and then launch the command (the "verb") then the command will not need to request the user select them. This is enabled using something called the pickfirst or implied selection set inside AutoCAD. To take advantage of this feature inside your commands the first thing to do is to use a special command-flag called "UsePickSet": this tells the AutoCAD editor not to clear the pickfirst set when the…

  • It's been a hectic week, between one thing and another, and I don't expect it to get better anytime soon: apart from anything else, my wife is due to give birth any day to our second child. We're both excited - and admittedly a little anxious - about it, and our 2 year-old seems to be feeding of that, which means none of us have ended getting much sleep of late. All good preparation, I suppose. 🙂 So I decided the path of least resistance for getting a blog entry out today was to look through some of the responses…