I've been using an existing post Getting user defined properties as a go by to try and set the values for the UDPs of Cogo Points using COM in VB.net. The example was great at getting started, but I'm stuck on the actual value being added to the point when the command is run. I'm not sure where the issue is - I'm getting an "Unspecified Error" on the ent.SetUserDefinedPropertyValue(udpProp, udpValue) line, but not sure what's causing. Maybe the value type "object" is passing as a string?
The first Sub creates the Class and the Property (appears to be working fine), The second Sub gets a user selected point and adds a udpValue to the udpProp that was jsut previously created.
- I've tried to create the udpClass and udpProp in the template and just add the udpValue, but I get the same error.
- I've checked the point entity and it appears to be getting the right information
Public Sub TLUDPNew() Using trans As Transaction = _ Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction() 'Testing code for User Defined Property for a point 'Setup UDP Class Dim udpClass As AeccUserDefinedPropertyClassification = _ oAeccDB.PointUserDefinedPropertyClassifications.Add("Drawing Label") 'Setup UDP Property for "Drawing Label" Class Dim udpProp As AeccUserDefinedProperty = _ udpClass.UserDefinedProperties.Add("UDPLabel", _ "Drawing Label", _ AeccUDPPropertyFieldType.aeccUDPPropertyFieldTypeString, _ False, False, 0, False, False, 0, False, Nothing, Nothing) trans.Commit() End Using
Public Sub TLUDPAdd() Using trans As Transaction = _ Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction() Dim udpClass As AeccUserDefinedPropertyClassification = oAeccDB.PointUserDefinedPropertyClassifications.Item("Drawing Label") Dim udpProp As AeccUserDefinedProperty = udpClass.UserDefinedProperties.Item("UDPLabel") Dim pmptEnt As PromptEntityOptions = New PromptEntityOptions("Select point") Dim entRes As PromptEntityResult = ed.GetEntity(pmptEnt) If entRes.Status = PromptStatus.OK Then If entRes.ObjectId.ObjectClass.DxfName.Equals("AECC_COGO_POINT") Then Dim ent As AeccPoint = entRes.ObjectId.GetObject(OpenMode.ForRead).AcadObject Dim udpValue As Object = "UDPValue Here" ent.SetUserDefinedPropertyValue(udpProp, udpValue) End If End If trans.Commit() End Using
As always, any help will be greatly appreciated.
Eric
Hi Eric,
With a quick scanning through your code snippet, I find you are accessing the COGO point as Readonly mode in this line >>>
Dim ent As AeccPoint = entRes.ObjectId.GetObject(OpenMode.ForRead).AcadObject
That could be a problem. Try with OpenMode.ForWrite
Also note that you can pass in the property name, or the property object for userDefinedProperty in SetUserDefinedPropertyValue() method.
From Jeff's earlier post, I think you will get the clue to resolve it.
Thanks,
Partha Sarkar
and here is another code snippet in C# .NET from our ADN IM Deblog -
http://adndevblog.typepad.com/infrastructure/2012/08/set-parcel-userdefined-property-from-api.html
Cheers,
I had tried the following line of code, changing the ForRead to ForWrite and also adding TryCast to an AeccPoint to be completly consistant with the example code.
Dim ent As AeccPoint = TryCast(entRes.ObjectId.GetObject(OpenMode.ForWrite).AcadObject, AeccPoint)
Also tried changing the udpProp from Item("UDPLabel") to Item(0)
Dim udpProp As AeccUserDefinedProperty = udpClass.UserDefinedProperties.Item(0)
But, Still no solution!
The example you provided in the Blog post shows how to set the name property, but doesn't show how to set the value.
Please help. This functionality is important to our workflow we're developing.
I also asked a more experienced developer in our agency for help and he also submitted this issue to our ADN paid subscription, and I was told ADN didn't supply a solution either.
Eric,
Have you found a solution to this yet?
I have a VS 2010 VB.NET app that updates Point UDP's. In this app for Wisconsin DOT point UDP's are popluated with station and offset information from the selected alignment.
This application iterates through all selected points. For each point it finds the station and offset to the selected alignment. The code snippet below picks up after that information has been gathered. It iterates through the UDP classifcations and calls the SETUPD function (at the end of this snippet) to update the appropriate value.
HTH.
Rod
iStart = 0 iEnd = aeccDB.PointUserDefinedPropertyClassifications.Count - 1 For i = iStart To iEnd udpClass = aeccDB.PointUserDefinedPropertyClassifications.Item(i) If StrComp(udpClass.Name, WISDOT_UDP_CLASS, vbTextCompare) = 0 Then For Each udpProp In udpClass.UserDefinedProperties bReturn = True If asALG1 Then Select Case LCase$(udpProp.Name) Case "sta1" bReturn = SetUDP(iPoint, udpProp, strStation, udpOverwrite) Case "alignment1" bReturn = SetUDP(iPoint, udpProp, strAlgNameUDP, udpOverwrite) Case "offset1" bReturn = SetUDP(iPoint, udpProp, strOffset, udpOverwrite) Case "aligndesc1" bReturn = SetUDP(iPoint, udpProp, strAlgDescUDP, udpOverwrite) Case "align_side1" bReturn = SetUDP(iPoint, udpProp, strSide, udpOverwrite) End Select Else Select Case LCase$(udpProp.Name) Case "sta2" bReturn = SetUDP(iPoint, udpProp, strStation, udpOverwrite) Case "alignment2" bReturn = SetUDP(iPoint, udpProp, strAlgNameUDP, udpOverwrite) Case "offset2" bReturn = SetUDP(iPoint, udpProp, strOffset, udpOverwrite) Case "aligndesc2" bReturn = SetUDP(iPoint, udpProp, strAlgDescUDP, udpOverwrite) Case "align_side2" bReturn = SetUDP(iPoint, udpProp, strSide, udpOverwrite) End Select End If Next 'udpProp In udpClass.UserDefinedProperties Exit For End If 'StrComp(udpClass.Name, WISDOT_UDP_CLASS, vbTextCompare) = 0 Next 'i = iStart To iEnd End If 'iPointG.ContainsPoint(iPoint.Number) Next 'iPoint In iPoints UpdatePointUDP = True Catch ex As Exception End Try End Function
Private Function SetUDP(ByRef iPoint As Autodesk.AECC.Interop.Land.AeccPoint, ByRef udpProp As Autodesk.AECC.Interop.Land.AeccUserDefinedProperty, ByVal udpValue As String, ByVal udpOverwrite As Boolean) As Boolean SetUDP = False Try If udpOverwrite Then iPoint.SetUserDefinedPropertyValue(udpProp, udpValue) SetUDP = True Else Try iPoint.GetUserDefinedPropertyValue(udpProp).ToString() SetUDP = True Catch iPoint.SetUserDefinedPropertyValue(udpProp, udpValue) SetUDP = True End Try End If Catch End Try End Function