
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
I'm currently working on an AutoCAD plugin in VB.net to utilize the "MapConnect" command, linked to around 70+ *.SHP files, to convert them to ACAD objects, while maintaining a list to conditionalize for later use as the values my differ. As we all know, Feature Data Objects (FDO) are not native to the ACAD IDE, which is why I've utilized the "Autodesk.Gis.Map.Platform" API (With a bit of a learning curve, I might add). I'm very proficient in Autolisp/VisualLisp, but have yet to come a solution for extracting the geometry of each selected FDO object. So far I have been able to compile a DLL in Visual Studio to, recursively, print the following. Layer, PropertyName, and the Value of each object, no matter the amount of properties in each object using the PropertyCount in a variable "Top". The following represents the output when passed to the command line:
Command: atr
Select Feature Data Objects in Map 3D: 1 found
Select Feature Data Objects in Map 3D:
7OF_OWNER_PubData_Parcels_Lay-OBJECTID-137937
9OF_OWNER_PubData_Parcels_Lay-PIN-0130300049
5OF_OWNER_PubData_Parcels_Lay-ACREAGE-92.9
9OF_OWNER_PubData_Parcels_Lay-ACRE_SOURC-Calculated
9OF_OWNER_PubData_Parcels_Lay-PARCEL_STA-Approved
5OF_OWNER_PubData_Parcels_Lay-TXT_ANGLE-0
5OF_OWNER_PubData_Parcels_Lay-SHAPE_Leng-0
7OF_OWNER_PubData_Parcels_Lay-ID-0
9OF_OWNER_PubData_Parcels_Lay-Field1-Null
9OF_OWNER_PubData_Parcels_Lay-Field2-Null
9OF_OWNER_PubData_Parcels_Lay-Field3-Null
9OF_OWNER_PubData_Parcels_Lay-Field4-Null
9OF_OWNER_PubData_Parcels_Lay-Field5-Null
9OF_OWNER_PubData_Parcels_Lay-Field6-Null
9OF_OWNER_PubData_Parcels_Lay-Field7-Null
9OF_OWNER_PubData_Parcels_Lay-Field10-Null
9OF_OWNER_PubData_Parcels_Lay-Field8-Null
5OF_OWNER_PubData_Parcels_Lay-Shape_STAr-679565.625
5OF_OWNER_PubData_Parcels_Lay-Shape_STLe-4492.44725671
13OF_OWNER_PubData_Parcels_Lay-Geometry-OSGeo.MapGuide.MgByteReader
All this to say, I'm not quite sure how to access the underlying data of geometry as it shows up as OSGeo.MapGuide.MgByteReader, which appears to be a collection in the properties tabs. I'm very new to this API and VB.net, so any help is appreciated! Also I've attached my code below, not including the references:
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.Gis.Map.Platform
Imports Autodesk.Gis.Map.Platform.Interop
Imports OSGeo.MapGuide
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Namespace FDOAttributes
Public Class myCommands
<CommandMethod("atr")>
Public Shared Sub Get_Selection()
Dim Cur_Map As AcMapMap = AcMapMap.GetCurrentMap()
Dim Map_Layers As MgLayerCollection = Cur_Map.GetLayers()
Dim Prompt_Sel_OP As PromptSelectionOptions = New PromptSelectionOptions()
Prompt_Sel_OP.MessageForAdding = "Select Feature Data Objects in Map 3D: "
Prompt_Sel_OP.SingleOnly = False
Dim Prompt_Sel_Res As PromptSelectionResult = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetSelection(Prompt_Sel_OP)
Try
If Prompt_Sel_Res.Status = PromptStatus.OK Then
Dim Selection_All As SelectionSet = Prompt_Sel_Res.Value
Dim Obj_Array() As ObjectId = Prompt_Sel_Res.Value.GetObjectIds()
Dim Obj_Arr_Top As Integer = Obj_Array.Length
Dim Progress As ProgressMeter = New ProgressMeter
Progress.Start("Analyzing Feature Data Objects: ")
Progress.SetLimit(Obj_Arr_Top)
Progress.Start()
For Each Obj_Id As ObjectId In Obj_Array
Progress.MeterProgress()
Dim Map_Selection_Base As MgSelectionBase = AcMapFeatureEntityService.GetSelection(Selection_All)
Dim Map_Layer As AcMapLayer = AcMapFeatureEntityService.GetLayer(Obj_Id)
Dim Feature_Reader As MgFeatureReader = Map_Selection_Base.GetSelectedFeatures(Map_Layer, Map_Layer.FeatureClassName, False)
Dim top As Integer = Feature_Reader.GetPropertyCount
Dim Tag As String
Dim Property_Type As Integer
Dim Field_Value
Dim Obj_Layer As String
While Feature_Reader.ReadNext
For index As Integer = 1 To top - 1
Tag = Feature_Reader.GetPropertyName(index).ToString
Property_Type = Feature_Reader.GetPropertyType(Tag)
Obj_Layer = AcMapFeatureEntityService.GetLayer(Obj_Id).Name.ToString
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(Property_Type.ToString)
Dim Class_Def As MgClassDefinition = Feature_Reader.GetClassDefinition()
Dim isNull As Boolean = Feature_Reader.IsNull(Tag)
If Property_Type = MgPropertyType.Double AndAlso isNull = False Then
Field_Value = Feature_Reader.GetDouble(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
ElseIf Property_Type = MgPropertyType.Int16 AndAlso isNull = False Then
Field_Value = Feature_Reader.GetInt16(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
ElseIf Property_Type = MgPropertyType.Int32 AndAlso isNull = False Then
Field_Value = Feature_Reader.GetInt32(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
ElseIf Property_Type = MgPropertyType.Int64 AndAlso isNull = False Then
Field_Value = Feature_Reader.GetInt64(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
ElseIf Property_Type = MgPropertyType.Single AndAlso isNull = False Then
Field_Value = Feature_Reader.GetSingle(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
ElseIf Property_Type = MgPropertyType.String AndAlso isNull = False Then
Field_Value = Feature_Reader.GetString(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
ElseIf Property_Type = MgPropertyType.Blob AndAlso isNull = False Then
Field_Value = Feature_Reader.GetBLOB(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
ElseIf Property_Type = MgPropertyType.Boolean AndAlso isNull = False Then
Field_Value = Feature_Reader.GetBoolean(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
ElseIf Property_Type = MgPropertyType.Byte AndAlso isNull = False Then
Field_Value = Feature_Reader.GetByte(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
ElseIf Property_Type = MgPropertyType.Clob AndAlso isNull = False Then
Field_Value = Feature_Reader.GetCLOB(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
ElseIf Property_Type = MgPropertyType.DateTime AndAlso isNull = False Then
Field_Value = Feature_Reader.GetDateTime(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
ElseIf Property_Type = MgPropertyType.Feature AndAlso isNull = False Then
Field_Value = Feature_Reader.GetFeatureObject(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
ElseIf Property_Type = MgPropertyType.Geometry AndAlso isNull = False Then
Field_Value = Feature_Reader.GetGeometry(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
ElseIf Property_Type = MgPropertyType.Raster AndAlso isNull = False Then
Field_Value = Feature_Reader.GetRaster(Tag)
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
Else
Field_Value = "Null"
Test_Property_Values(Field_Value.ToString, Obj_Layer, Tag)
End If
Next
End While
Next
Progress.Stop()
End If
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction.Commit()
Catch e As Exception
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(e.ToString & vbCrLf)
End Try
End Sub
Public Shared Sub Test_Property_Values(Value As String, Layer As String, Prop As String)
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(Layer & "-" & Prop & "-" & Value & vbCrLf)
End Sub
End Class
End Namespace
Thanks in Advance!
Michael Luckett
Solved! Go to Solution.