Many people have asked how they can turn an AutoCAD entity or selection set into a set of Topobase features. This comes up because within AutoCAD, Topobase features for a class are presented to the user as layer which has a single corresponding FDO bulk feature in the AutoCAD drawing. Manipulating this entity for selection and highlighting is challenging.
However, given that you have access to the Topobase context as described in Accessing Documents from AutoCAD Commands you can convert a
selection set into FeatureList using a combination of the Map Platform API and Topobase API.
The crucial step is the conversion from a set of AutoCAD entities to an MgSelectionBase object using the
AcMapFeatureEntityService:
selection = AcMapFeatureEntityService.GetFeatures (ObjectIdCollection);
Another common use-case is to be able to programmatically ask the user to select a Topobase feature on the screen. This works fine using
Document.Map.GetFeatures() from within a workflow, but when executed from an AutoCAD command it will generate an error that
There is an active command in Topobase! Abort first the pending command and try again. This is because Topobase checks and finds that an AutoCAD command is
running - but this is the one calling GetFeatures!
One way around this is to select your own features at a user chosen point with a spatial query over appropriate feature classes using FeatureClass.GetFeatures (true, Spatial_Mask.Struct, Geometry).
Both of these use-cases are demonstrated in a sample program, which you can download as a ZIP file of a complete project using the link below.
To build this project, define the environment variable TopobaseClientDirectory to point to the Topobase Client directory and execute the solution file:
C:>set TopobaseClientDirectory=C:\Program Files\Autodesk Topobase Client 2009
C:>FeatureSelector.sln
Build the solution and then run Topobase client and from the AutoCAD prompt execute either SelectFeatures or PickFeatures:
Command: SelectFeatures
Command: PickFeatures
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.