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.
Philippe Leefsma, from DevTech EMEA, and Gopinath Taget, from DevTech Americas, 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.
The API distribution includes a single VS 2008 solution – as the API has been implemented using ObjectARX, which currently requires the use of VS 2008 – 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.
For people such as myself using VS 2010, the best thing to do is to load this solution – converting the various projects – and then unload the projects you don’t need: AdnAssocConstraintAPI, AdnAssocConstraintAPIMgd and ArxConstraintAPITest. You will then need to set a “Reference Path” in the remaining project (MgdConstraintAPITest), pointing it to the compiled AdnAssocConstraintAPIMgd.dll file in the “bin resource” folder, as well as to the usual AcDbMgd.dll and AcMgd.dll files.
Beyond that, the implementation 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)
Thanks to Philippe and Gopi for their hard work on this very helpful API!