Reading Object Data from AutoCAD MAP 3D in Civil 3D API

Reading Object Data from AutoCAD MAP 3D in Civil 3D API

mohamed_ebrahim3016
Contributor Contributor
577 Views
2 Replies
Message 1 of 3

Reading Object Data from AutoCAD MAP 3D in Civil 3D API

mohamed_ebrahim3016
Contributor
Contributor

Hi everyone 

I’m working with a DWG file that originated from Autodesk Map 3D, and I’m trying to programmatically read the attribute data that appears under the “Design” tab in the Civil 3D Properties panel.

I’ve already referenced the main Map 3D API assemblies:

  • Autodesk.Gis.Map.Platform.dll

  • Autodesk.Gis.Map.ObjectData.dll

  • Autodesk.Gis.Map.Utilities.dll

and tried multiple approaches using HostMapApplicationServices.Application.ActiveProject.ODTables and GetObjectTableRecords().
However, I still can’t access the same data that’s visible in the Properties → Design tab — it always returns empty (Records.Count = 0).

Has anyone successfully read this data through the Map 3D or Civil 3D APIs?
Is it possibly stored in sub-entities, feature classes (FDO), or another structure that isn’t directly accessible through ObjectData.Table?

Any insights or working examples would be greatly appreciated.

Thanks in advance,
Mohamed

0 Likes
Accepted solutions (2)
578 Views
2 Replies
Replies (2)
Message 2 of 3

Jeff_M
Consultant
Consultant
Accepted solution

This is code I use to populate a WPF window and make edits to the OD.

            var doc = Application.DocumentManager.MdiActiveDocument;
            var ed = doc.Editor;
            var ssOpt = new PromptSelectionOptions
            {
                MessageForAdding = "\nSelect object to edit ObjectData:",
                SingleOnly = true
            };
            var ssFilter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "*POLYLINE,LINE,INSERT,CIRCLE,ARC") });
            var ssRes = ed.GetSelection(ssOpt, ssFilter);
            if (ssRes.Status != PromptStatus.OK)
                return;
            ODViewModel mview = null;
            ODDataWindow form = null;
            using (var doclock = doc.LockDocument())
            {
                var tables = HostMapApplicationServices.Application.ActiveProject.ODTables;
                while (ssRes.Status == PromptStatus.OK)
                {
                    ObjectId id = ssRes.Value.GetObjectIds()[0];
                    using (var records = tables.GetObjectRecords(0, id, Constants.OpenMode.OpenForRead, true))
                    {
                        if (records == null || records.Count < 1)
                        {
                            ed.WriteMessage("\nNo ObjectData attached to this entity, please select another.");
                            ssRes = ed.GetSelection(ssOpt, ssFilter);
                            continue;
                        }
                        mview = new ODViewModel(records);
                    }
                    form = new ODDataWindow(mview);
                    if (Application.ShowModalWindow(form) == true)
                    {
                        UpdateOD(id);
                    }
                    ssRes = ed.GetSelection(ssOpt, ssFilter);
                    mview = null;
                    form = null;
                }
            }

 

And these are the using statements, with the only Map API reference being ManagedMapApi.dll:

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Gis.Map;
using Autodesk.Gis.Map.ObjectData;
using System;
using System.Collections.Generic;
using Constants = Autodesk.Gis.Map.Constants;

 

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 3

mohamed_ebrahim3016
Contributor
Contributor
Accepted solution

Thanks, Jeff, that's very clear. I'd struggled with MAP references.

Also, I wanna drop this method here as I continue it with my model classes. 

 

        private ObjectData CollectObjectDataSchema()
        {
            var result = new ObjectData();

            Tables odTables = HostMapApplicationServices.Application.ActiveProject.ODTables;
            var tableNames = odTables.GetTableNames();

            foreach (string tName in tableNames)
            {
                Table table = odTables[tName];
                if (table == null) continue;

                var odTable = new ODTable
                {
                    TableName = tName
                };

                FieldDefinitions defs = table.FieldDefinitions;
                for (int i = 0; i < defs.Count; i++)
                {
                    FieldDefinition fd = defs[i];
                    odTable.Fields.Add(new ODFieldDefinition
                    {
                        Name = fd.Name,
                        Type = fd.Type.ToString()
                    });
                }

                result.Tables.Add(odTable);
            }

            return result;
        }

// Model Classes
    public partial class ObjectData : ObservableObject  // Holds all table schemas in the DWG
    {
        [ObservableProperty] private ObservableCollection<ODTable> _Tables = []; 
    }

    public partial class ODTable : ObservableObject  // Describes one Object Data table (name + field list)
    {
        [ObservableProperty] private string? _TableName;
        [ObservableProperty] private ObservableCollection<ODFieldDefinition> _Fields = [];
    }
    public partial class ODFieldDefinition : ObservableObject  // Describes one column (field) in a table
    {
        [ObservableProperty] private string? _Name;
        [ObservableProperty] private string? _Type;
    }

 

 

 

0 Likes