Issue
I need to get the value of a User-Defined Property of a COGO point. Is there any API for this?
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()


Leave a Reply to Partha SarkarCancel reply