Civil 3D .NET API: COGO Point: How to read a User-Defined Property?

By Marat Mirgaleev

Issue

I need to get the value of a User-Defined Property of a COGO point. Is there any API for this?

image

 

Solution

Yes, there is the CogoPoint.GetUDPValue() method for it. But it requires a parameter of one of the following types: UDPBoolean, UDPDouble, UDPEnumeration, UDPInteger or UDPString.

All the User-Defined Properties (UDPs) for COGO points can be found in this collection: CivilApplication.ActiveDocument.PointUDPs. So, I’ve created a small function to find the respective UDP (called “MM1” on the screenshot) in this collection.

' Reading a User-Defined Property of a COGO point.      '=================================================================           ' Find the UDP amongst all the UDPs in the document      Private Function FindUDP( i_UDPname As String ) As UDPString             Dim foundUDP As UDPString = Nothing        For Each UDP As UDP In CivilApplication.ActiveDocument.PointUDPs          If UDP.Name = i_UDPname Then            foundUDP = TryCast(UDP, UDPString)            Exit For          End If        Next             Return foundUDP           End Function                 _      Public Sub ReadUDPOfCoGoPoint()             Try               Dim ed As Editor =                     Application.DocumentManager.MdiActiveDocument.Editor               ' Select a COGO point          Dim selectPointsResult As PromptEntityResult =                             ed.GetEntity(vbCrLf + "Select a COGO Point:")          If selectPointsResult.Status  PromptStatus.OK Then            Return          End If               Dim db As Database =                    Application.DocumentManager.MdiActiveDocument.Database          Using tr As Transaction =                                  db.TransactionManager.StartTransaction()                 Dim dbObj As Autodesk.AutoCAD.DatabaseServices.DBObject =              tr.GetObject(selectPointsResult.ObjectId, OpenMode.ForRead)            Dim pt As CogoPoint = TryCast(dbObj, CogoPoint)                 Const UDPname As String  = "MM1"  ' The property we are                                               ' looking for            Dim UDP As UDPString = FindUDP( UDPname )                                               ' See this function above            If UDP Is Nothing Then              Return            End If                 Dim s As String = pt.GetUDPValue(UDP)            ed.WriteMessage( String.Format( vbCrLf+"MM1={0}", s ) )                 tr.Commit()               End Using             Catch e As System.InvalidOperationException          System.Windows.Forms.MessageBox.Show(               "Probably, this point does not have the MM1 property set" )            Catch e As System.Exception          System.Windows.Forms.MessageBox.Show(               "Exception in ReadUDPOfCoGoPoint():" _               + vbCrLf + e.Message)        End Try           End Sub ' ReadUDPOfCoGoPoint()

Comments

2 responses to “Civil 3D .NET API: COGO Point: How to read a User-Defined Property?”

  1. Michael J. Smith Avatar
    Michael J. Smith

    Will this solution work on Civil 3D 2012?

  2. Hi Michael ,
    I don’t have Civil 3D 2012 currently installed in my machine to confirm, but I think it won’t work in 2012 release as COGO point .NET API was not exposed in 2012 release. If you have 2012 installed in your machine, please check the Civil 3D .NET API assembly.
    Thanks,
    Partha

Leave a Reply to Partha SarkarCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading