Read FDO Features using Map 3D Geospatial Platform API

By Partha Sarkar

If you are looking for a way to access the FDO features and read the feature attributes in Map 3D using Geospatial Platform API, then the following C#.NET code snippet might be useful to you. This code snippet shows how to use the Geospatial Platform API in AutoCAD Map 3D and access the FDO Features.

// Get the Map Object
AcMapMap currentMap = AcMapMap.GetCurrentMap();
 
// Prompt user to Select Feature in Map
PromptSelectionOptions psop = new PromptSelectionOptions();
psop.MessageForAdding = "Select the FDO Feature in Map 3D to read Data : ";
psop.SingleOnly = true;
PromptSelectionResult psResult = ed.GetSelection(psop);
 
if (psResult.Status == PromptStatus.OK)
{
    SelectionSet selSet = psResult.Value;
 
    // Get Map Selectionset from AutoCAD SelectionSet
    MgSelectionBase mapSelBase = AcMapFeatureEntityService.GetSelection(selSet);
    AcMapLayer mapLayer = AcMapFeatureEntityService.GetLayer(psResult.Value[0].ObjectId);
 
    //Get the ID of the selected Parcel
    MgFeatureReader ftrRdr = mapSelBase.GetSelectedFeatures(mapLayer, mapLayer.FeatureClassName, false);
 
    while (ftrRdr.ReadNext())
    {
        MgClassDefinition cd = ftrRdr.GetClassDefinition();
 
        //this is just an example; change this according to your FDO data field
 
        String ownerName = ftrRdr.GetString("STNAME");
        ed.WriteMessage("n Parcel Owner Name :" + ownerName.ToString());
    }                       
}
trans.Commit();

Comments

2 responses to “Read FDO Features using Map 3D Geospatial Platform API”

  1. Hi Partha Sarkar,
    I would like to ask you about “ed.” and “trans”
    When I was compiling , VS2012 Alerted me that ” ‘ed’ name isn’t context.
    Could you please tell me more details explanations.
    Thank you.

  2. Hi Kim,
    Use this :
    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
    Transaction trans = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction();
    Hope this helps!
    Thanks,
    Partha Sarkar
    ADN

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading