AutoCAD .NET
-
In a recent webcast, Gopinath Taget, from our DevTech Americas team, showed how to use the Brep API from a .NET application: something that was made possible in AutoCAD 2009. The Brep API in AutoCAD allows you to traverse the boundary representation of a Solid3d object. Without going into specifics - as this isn't really an area of AutoCAD I've had much reason to use, over the years - I went ahead and took the sample Gopi showed in his webcast and modified it for the purposes of this blog. The following C# code traverses the Brep of a selected…
-
This is a follow-up to the last post, where we looked at some C# code to generate a Polyline from a Region. Fernando very kindly pointed out that complex Regions would not be handled properly, so I went away and enhanced the RTP command to create separate Polylines for each of the loops (or nested Regions) contained in a Region we're trying to explode. The significant changes were: To return a collection of objects, rather than a single Polyline To recurse when we find a Region in the results of the Explode() call Otherwise the code is reasonably similar, although…
-
Thanks to Philippe Leefsma, from our DevTech team in Europe, for providing the code used as the basis for this post. I took Philippe's code and enhanced it to support arcs and to check for disconnected segments (which in theory should never happen, but it's better to be safe than to loop infinitely :-). When you explode a region in AutoCAD, the resultant geometry is in the form of lines and arcs. The following technique shows how to take the lines and arcs returned by the Explode() function (which doesn't perform the equivalent of the EXPLODE command in AutoCAD, remember:…
-
In response to these recent posts, I received a comment from Nick: By any chance would it be possible to provide an example to prevent a user from using the EXPLODE command for a given block name? I delved into the ADN knowledgebase and came across this helpful ObjectARX DevNote, which I used to create a .NET module to address the above question. Here's the C# code, which should contain enough comments to make it self-explanatory: using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; namespace ExplosionPrevention { public class Commands { private Document _doc; private Database…
-
Another big thank you to Jeremy Tammik, from our DevTech team in Europe, for providing this elegant sample. This is another one Jeremy presented at the recent advanced custom entity workshop in Prague. I have added some initial commentary as well as some steps to see the code working. Jeremy also provided the code for the last post. We sometimes want to stop entities from being modified in certain ways, and there are a few different approaches possible, for instance: at the simplest - and least granular - level, we can place entities on locked layers or veto certain commands…
-
The code in the following two posts was provided by Jeremy Tammik, from our DevTech team in Europe, who presented it at an advanced custom entity workshop he delivered recently in Prague to rave reviews. I've formatted the code to fit the blog and added some commentary plus steps to see it working. Thank you, Jeremy! Those of you who are familiar with the workings of AutoCAD Architecture - and especially the Object Modeling Framework - will know of the very cool ability for entities to be anchored to one another. This works because graphical ACA classes derive from a…
-
Another juicy tidbit from an internal Q&A session. The question... How can I throw an exception from within a modal form on mine inside AutoCAD, and catch it in the calling command? I have tried try/catch, but nothing seems to work. Here's my command definition: using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.Runtime; using System.Windows.Forms; using MyApplication; using acApp = Autodesk.AutoCAD.ApplicationServices.Application; namespace CatchMeIfYouCan { public class Commands { [CommandMethod("CATCH")] static public void CatchDialogException() { try { MyForm form = new MyForm(); DialogResult res = …
-
My manager is currently sailing back from Honolulu to San Francisco, after his boat came 2nd in its division in the 2008 Pacific Cup (congratulations, Jim! :-), so I'm spending more time on management-related activities than I would normally. Which means I'm getting less time to spend on the fun stuff, such as researching blog posts: I'm plundering what I can from my email archives, but my output may feel a little thin over the next week or two. Here's some information from an internal discussion that I thought might be of general interest. The question: Why is it important…
-
Thanks to Gopinath Taget, from DevTech Americas, for letting me know of this tool's existence. I've often battled to create Platform Invoke signatures for unmanaged C(++) APIs in .NET applications, and it seems this tool is likely to save me some future pain. The tool was introduced in an edition of MSDN Magazine, earlier this year. [For those unfamiliar with P/Invoke, I recommend this previous post.] While the Interop Assistant can be used for creating function signatures to call into .NET assemblies from unmanaged applications, I'm usually more interested in the reverse: calling unmanaged functions from .NET. Let's take a…
-
This question came in recently from a developer: I've noticed a lot of talk about cad standards in my circles - any chance of a post on creating a CAD Standards plugin for use in the AutoCAD CAD Standards checker that companies could take and run with to produce their custom checks? For example, is the titleblock to company standard and inserted in the right space, are the xrefs inserted at 0,0 etc. I thought this was an interesting one to handle: back when I was based in San Rafael I (along with members of my team) worked closely with…