Author Topic: Accessing C3D 2009 Parcels causing an exception error  (Read 2075 times)

0 Members and 1 Guest are viewing this topic.

surveyor_randy

  • Guest
Accessing C3D 2009 Parcels causing an exception error
« 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."

Code: [Select]
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!

Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: Accessing C3D 2009 Parcels causing an exception error
« Reply #1 on: February 06, 2009, 10:36:11 AM »
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.
Code: [Select]
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!                  

surveyor_randy

  • Guest
Re: Accessing C3D 2009 Parcels causing an exception error
« Reply #2 on: February 06, 2009, 10:54:23 AM »
Thanks for the sample Jeff!  I really appreciate it!  :-)