By Philippe Leefsma
This post is an updated version of Kean's post about the simplified constraint API we developed a while ago. At the time we posted it, this AutoCAD DevBlog wasn’t existing yet, so the reason why I’m posting that myself today is because, being the main author of that library, it will be easier to manage comments directly rather than through Kean’s blog.
In the 2010 release, we introduced 2D geometric constraints to AutoCAD. The feature was implemented using AutoCAD’s low-level – and very powerful – Associative Framework, which has subsequently been used to implement features such as parametric surfaces in AutoCAD 2011 (more information on that here). Our initial API implementation for creating and accessing geometric constraints (which you can find out more about via the DevTV session linked to from this previous post) in many ways reflects the low-level nature of the underlying framework: it was unfortunately just a bit too complicated for most mortals to get to grips with.
Gopinath Taget, a colleague from DevTech Americas, and myself have worked with our Engineering team to develop a “high-level” API for constraints inside AutoCAD, which does a great job of abstracting away much of this complexity.
includes VS2008, VS2010 and VS2012 solutions containing projects for the C++ API, the mixed-mode layer exposing this to .NET and a test project for each of these managed and unmanaged APIs.Beyond that, a custom implementation using that library should be relatively straightforward: I suggest trying out the various commands implemented in the test project to get a feel for what’s possible, as well as taking a look at the compiled help-file provided in the Help folder.
Here are a list of these commands with a brief description of what they do:
- MGHLCOIN – creates a coincident constraint
- MGHLPAR – creates a parallel constraint
- MGHLPERP – creates a perpendicular constraint
- MGHLCONC – creates a concentric constraint
- MGHLCOLIN – creates a co-linear constraint
- MGHLHOR – creates a horizontal constraint
- MGHLVERT – creates a vertical constraint
- MGHLFIX – creates a fix constraint
- MGHLTAN – creates a tangent constraint
- MGHLG2SM – creates a smooth constraint
- MGHLSYM – creates a symmetric constraint
- MGHLEQLN – creates a equal length constraint
- MGHLEQRAD – creates a equal radius constraint
- MGHLDIMALIGN – creates an aligned dimensional constraint
- MGHLPARAM – illustrates several functionalities of AssocUtil Parameter API (query, creation, modification, renaming)
Feel free to post your feedback about the library and report any issue you may encounter while working with it.