TheSwamp
Code Red => .NET => Topic started by: surveyor_randy on February 06, 2009, 09:14:51 AM
-
I haven't worked with parcels yet in .NET and am trying to create a legal description writer. Just trying to get my feet wet, I came up with the following code to access parcels and it is throwing an exception error: "Unable to cast COM object of type 'System.____ComObject' to interface type 'Autodesk.AECC.Interop.Land.AeccParcelSegment....... No such interface supported."
For Each oParcel As AECC.Interop.Land.AeccParcel In m_oAeccDb.Sites.Item(0).Parcels
For Each oParcelSegment As AECC.Interop.Land.AeccParcelSegment In oParcel.ParcelLoops
If TypeOf oParcelSegment Is AECC.Interop.Land.AeccParcelSegmentLine Then
Dim oLine As AECC.Interop.Land.AeccParcelSegmentLine = oParcelSegment
ed.WriteMessage(vbCrLf & "Distance = " & oLine.Length)
ElseIf TypeOf oParcelSegment Is AECC.Interop.Land.AeccParcelSegmentCurve Then
Dim oLine As AECC.Interop.Land.AeccParcelSegmentCurve = oParcelSegment
ed.WriteMessage(vbCrLf & "Radius = " & oLine.Radius)
End If
Next
Next
I don't understand the error, could someone kindly give me a push in the right direction in what I am doing wrong to access parcels in this manner? Thank you!
-
Here's some quick code that does what you are trying in this example. Note the 2 big things, ParcelLoops can have more than 1 Loop so you need to specify which loop (I think that this will normally be 0, I haven't investigated why there would be more than 1..perhaps islands in the middle?), then you must get the ParcelSegmentElement.
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AECC.Interop.Land
Imports Autodesk.AECC.Interop.UiLand
Imports mgdAcadApp = Autodesk.AutoCAD.ApplicationServices.Application
Public Class Class1
<CommandMethod("TestMe")> _
Public Sub TestMe()
Dim m_AcadApp As AcadApplication
Try
m_AcadApp = Application.AcadApplication()
Dim m_oAeccApp As New AeccApplication()
m_oAeccApp.Init(m_AcadApp)
Dim m_oAeccDoc As AeccDocument
m_oAeccDoc = m_oAeccApp.ActiveDocument
Dim ed As Editor
ed = mgdAcadApp.DocumentManager.MdiActiveDocument.Editor
Dim strSiteName As String = "Site2"
Dim oParcels As AeccParcels = m_oAeccDoc.Sites.Item(strSiteName).Parcels
Dim oparcel As AeccParcel
For Each oparcel In oParcels
For Each oParcelSegment As AeccParcelSegmentElement In oparcel.ParcelLoops(0)
If TypeOf oParcelSegment Is AeccParcelSegmentLine Then
Dim oLine As AeccParcelSegmentLine = oParcelSegment
ed.WriteMessage(vbCrLf & "Distance = " & oLine.Length)
ElseIf TypeOf oParcelSegment Is AeccParcelSegmentCurve Then
Dim oLine As AeccParcelSegmentCurve = oParcelSegment
ed.WriteMessage(vbCrLf & "Radius = " & oLine.Radius)
End If
Next
Next
Catch
MsgBox(Err.Description() & Err.Number)
End Try
exit_here:
End Sub
End Class
Note that this is not great code...I throws some warning messages, but it works and is all I have time for right now.... Good luck!
-
Thanks for the sample Jeff! I really appreciate it! :-)