Every so often, a request surfaces to be able to convert some of the more exotic AutoCAD drawing entities into Topobase features. Out of the box, Topobase will convert standard entities like points, blocks, lines and polylines using the Create new Feature from Geometry context menu. But, there are a few standard AutoCAD entities that aren’t converted. Most requested among these are dimensions and hatches.
These are complex entities, having deep internal structure within an AutoCAD drawing, so their conversion is not straight-forward and heavily subject to interpretation. This post provides only a sample conversion for these features – but of course it includes source code, so you are free to provide your own implementation if it doesn’t fit your needs.
Dimensions
The dimension entity in AutoCAD is really just a placeholder for an anonymous block that has the actual entities you think of as a dimension. These are the dimension line, the extension lines, the arrow heads, the dimension text and (usually invisible) dimension definition or reference points at the ends of the extension lines and on the dimension line. Most of these map directly to the dimension feature classes of the Topobase Dimension extension module which are created when you add the dimension extension to a Topobase document. Of interest to this post are the Aligned Dimension, Aligned Dimension (line), Aligned Dimension (point) and Aligned Dimension (label), which is the label class for aligned dimension lines.
When a dimension is created, an Aligned Dimension feature is inserted that acts as the parent feature for all other classes. Zero or more Aligned Dimension Lines are inserted with various values of LINE_TYPE, e.g. ‘AL’ and ‘HL’, standing for abscissa line and helper line, depending on the dimensioning command used. If the lines are not supposed to be symbolized (because they are hidden) the LINE_TYPE has an underscore suffix. Two Aligned Dimension Point features are inserted at the ends of the dimension line, and these can be used to symbolize the arrowheads. The Dimension Label is inserted above the dimension line. The operation of the dimension workflows are described in the online documentation.
If one wants to convert an AutoCAD dimension, one must map the entities in the anonymous dimension block to the proper feature classes and create the right relationships; that is, it isn’t enough to explode the dimension and convert the pieces. Even if you convert all the fragments (points, lines, solids, blocks and text), and choose the right feature class for each of the fragments, the relation between them would be lost. So the supplied program converts dimensions as a gestalt – converting the geometry and properties of important fragments and establishing the correct relations between the elements.
A little guesswork is required, in the form of heuristics, but the AutoCAD associative dimensions are regular enough in internal structure to make this work – at least for HORizontal, VERtical and ALIgned dimensions in the AutoCAD sense. Other dimension types such as RADius and ANGle aren’t supported by the Topobase data model.
The conversion process operates in two phases. In the first phase the necessary features are instantiated. These are given only enough temporary geometry to correctly auto-insert the label. In the second phase, the program iterates over the anonymous dimension block entities and assigns the actual geometry and label details.
To get the same look-and-feel as AutoCAD dimensions, there must be corresponding symbology associated with the label feature classes. For example, the default AutoCAD arrow heads need a corresponding point symbolization for the Aligned Dimension (point) feature class with appropriate rotation and scaling. The label too needs symbolization to get the correct text height, rotation and – we cheat a bit here – an obscuring white background so that the dimension line appears to be broken in two by the label.
The results are shown below. I leave it up to the reader to figure out which are AutoCAD dimension entities and which are Topobase features. The display model that was used is also supplied. It contains the standard AutoCAD dimension arrowhead as an enhanced stylization symbol.
Hatches
The AutoCAD hatch command is very powerful, generating outer rings and nested holes and islands for very complex geometry with a very small amount of user input. For example, one can use a crossing window to select all the entities comprising the hatch boundaries or pick selected interior points and have AutoCAD figure it out and create the hatch in one step. To perform the same operations manually in Topobase would be tedious.
The supplied sample code converts hatches into a Polygon or MultiPolygon features. There isn’t much to describe about the procedure without delving into the math involved. Suffice it to say that it examines and copies the exterior and interior loops that define the hatch boundaries into the geometry of a polygon, making it a multi-polygon if multiple exterior loops are detected.
Sample Program
The whole program is packaged as a simple EntityConverter.dll with an exposed ConvertEntities command. It asks the user to select one or more AutoCAD entities and converts the selected dimensions and hatches (and solids and polylines just for good measure) into features. As mentioned above, the target classes for dimensions are fixed by the Dimension extension, but the target feature class for polylines and hatches are requested the first time they are needed, or can be set using the commands SelectPolyLineFeatureClass and SelectPolygonFeatureClass. It could easily be made into a workflow that allows the user to choose these and various other options that are currently hard-coded.
To run the program, you will need a document that has the Dimension extension. Copy the EntityConverter.dll into the Topobase bin directory. In Topobase Client, use the NetLoad command and choose the DLL. Create one or more hatches or dimensions using AutoCAD and then invoke the ConvertEntities command, which asks you to select the entities to be converted.
To build the program, define the environment variable TopobaseClientDirectory to be the directory where you have installed Topobase client. If you are using the Topobase 2011 Beta, you will need to change assembly references as follows:
Assembly References
| TB2010 References | TB2011 References |
| Autodesk.Map.Platform.dll | Autodesk.Map.Platform.Core.dll |
| OSGeo.MapGuide.PlatformBase.dll |
| OSGeo.MapGuide.Foundation.dll |
AUTODESK DOES NOT GUARANTEE THAT YOU WILL BE ABLE TO SUCCESSFULLY DOWNLOAD OR IMPLEMENT ANY SAMPLE CODE. SAMPLE CODE IS SUBJECT TO CHANGE WITHOUT NOTICE TO YOU.
AUTODESK PROVIDES SAMPLE CODE "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE. IN NO EVENT SHALL AUTODESK OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS
OF DATA, OR LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, THAT MAY OCCUR AS A RESULT OF IMPLEMENTING OR USING ANY SAMPLE CODE, EVEN IF AUTODESK OR ITS SUPPLIERS
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Download EntityConverter