AutoCAD .NET

  • It's been quite a week... I was attending Autodesk's annual One Team Conference in Las Vegas, and had a number of meetings before, during and afterwards (hence my inability to make any posts whatsoever since Sunday). It was hectic, but a great event - the highlight for me was the keynote address on Wednesday by none other that Bill Clinton, the 42nd President of the United States! Wow. Anyway, late last week it came to my attention that a presentation of mine had made it onto one of Autodesk's public websites. Thanks to posts on Jimmy Bergmark's and Scott Sheppard's…

  • This very good question came in by email from Patrick Nikoletich: I was wondering what the preferred method for overriding the default "Open" common dialog in AutoCAD 2007 would be? I can catch the event but can't send AutoCAD a command to cancel the request so I can launch my Win Form instead. This is quite a common requirement - especially for people integrating document management systems with AutoCAD. The simplest way to accomplish this - and this technique goes back a bit - is to undefine the OPEN command, replacing it with your own implementation. The classic way to…

  • The bulk of this code was donated by Virupaksha Aithal, a member of our DevTech team in India. It's fairly common for developers to want to check for user input from time to time during long operations, especially to see whether the user wants to cancel the current activity. In VB you'd use DoEvents() to enable messages to be processed by the application's message loop and in ObjectARX you'd use acedUsrBrk(). So how to do this in .NET? The answer is to use a message filter. This allows us to check on user-input events... we still call DoEvents, as with…

  • This question came in a couple of weeks ago from csharpbird, and I promised myself to turn it into a post: The Hatch class of the current AutoCAD version does not provide the OriginPoint property.How to get/set the OriginPoint of the Hatch object using P/Invoke? The reason I wanted to delay making an official post is that I have good news (that I couldn't talk about until the product was announced): the Autodesk.AutoCAD.DatabaseServices.Hatch object now has an Origin property in AutoCAD 2008. ๐Ÿ™‚ But this does raise an interesting topic - how to get at information that isn't available through…

  • This comment came in overnight from Brian: I was hoping to work out how to get the Entity from the handle and then erase it, from your posts, I've learned a lot but not found the answer to this one yet, I still have a mountain to climb. (I'm using VB.NET, I've done it in VB6 +COM, even in Lisp but .NET ....) As it's such a good question, I'm making a post out of it... The trick is to go from a hexadecimal string to a 64-bit integer (using System.Convert.ToInt64(str,16); which specifies the string as being "base-16" or hexadecimal).…

  • In the previous two posts we looked at the new ObjectARX samples and the new .NET samples available for AutoCAD 2008. AutoCAD 2008 also exposes a number of new APIs (and enhancements to old ones) for which we don't have new SDK samples. Take a look of the 'Migration Guide for Applications' for a comprehensive list of new classes and new methods and properties within classes. Check the AutoCAD Managed Class Reference for Managed equivalents. And once again - let me know if there are any of specific interest to you, and we'll see what we can do. ๐Ÿ™‚ Layers…

  • In the last post we looked at the new ObjectARX samples for AutoCAD 2008, while today we're looking at the .NET samples. In the next post we'll look at the other new APIs available with AutoCAD 2008. With the exception of custom objects, .NET now includes essentially all the functionality available in ObjectARX. While the ObjectARX samples are a good reference for .NET programmers, we've also bolstered our collection of .NET samples. Unfortunately, we were unable to add full .NET documentation for this release, but rest assured that our Technical Publications team is working hard on it. In the meantime,…

  • In the last post we looked at some code that combined user-input from the AutoCAD command-line with .NET reflection to determine an object type, a property belonging to that type, and the value to which we want to change that property on instances of that type (phew!). Here's where we look at hooking that up with some code to work recursively through the drawing database and make the changes to the actual objects. Firstly, let's look at some C# code to check the type of an entity, and then - as appropriate - to query the property's value and to…

  • I ended up having a fun weekend, in spite of the circumstances. My wife and eldest son were both sick with a cold (which, inevitably enough, I now feel I'm coming down with myself), so we mostly stayed around at home. So I got to spend a little time working on an idea that came to me after my last post. While the code I provided last time does pretty much exactly what was asked of it (allowing the person who requested it to change the colour of every entity in the modelspace โ€“ whether in nested blocks or not…

  • Someone asked me earlier today how to iteratively change the color of entities inside blocks. The following code uses a recursive helper function to iterate down through the contents of a block, changing the various entities (other than block references, for which we simply recurse) to a specified colour. Here's the C# code: using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Colors; namespace BlockTest {   public class BlockCmds   {     [CommandMethod("CC")]     public void ChangeColor()     {       Document doc =         Application.DocumentManager.MdiActiveDocument;       Database db = doc.Database;     …