Is there any chance to get user defined properties using .NET API for civil 2012?
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
Solved by Jeff_M. Go to Solution.
Solved by Jeff_M. Go to Solution.
Thanx for your answer! Getting UDP info without getting value of the property is useless in my opinion. I've found this possibility, but there is no any sense just to know the type of the value. Anyway thank you for preventing me from wasting my time looking for the solution.
It seems like this method GetUserDefinedPropertyValue(UDPname) doesn't work. Could you please send me working example source code?
here is my source:
Point.GetUserDefinedPropertyValue(udpClassification.UserDefinedProperties.Item(0).Name).ToString()
and it doesn't work. it shows some error which means "cannot create COM object", but point objet already exists, udpClassification as well. It looks like there is no implementation for the method.
I think that because these are COM objects, you need to break down the process a bit. Testing in the Tutorial drawing "Points-4c", I manually edited the point # 1384's "MH_Material" UDP to be Concrete. I then tested the following C# code and selected that point. It all works as expected. Make sure to add the appropriate references and usings.
[CommandMethod("ShowUDP")] public static void ShowUDP() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; PromptEntityOptions pmptEnt = new PromptEntityOptions("\nSelect entity:"); PromptEntityResult entRes = ed.GetEntity(pmptEnt); if (entRes.Status == PromptStatus.OK) { if (!entRes.ObjectId.ObjectClass.DxfName.Equals("AECC_COGO_POINT")) return; AeccApplication aeccApp = new AeccApplicationClass(); aeccApp.Init((AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication); AeccDatabase aeccdb = (AeccDatabase)aeccApp.ActiveDocument.Database; AeccUserDefinedPropertyClassification udpClass = aeccdb.PointUserDefinedPropertyClassifications.Item("Manhole UDP"); AeccUserDefinedProperty udpProp = udpClass.UserDefinedProperties.Item("MH_Material"); using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()) { AeccPoint ent = (AeccPoint)entRes.ObjectId.GetObject(OpenMode.ForRead).AcadObject; object udpval = ent.GetUserDefinedPropertyValue(udpProp); ed.WriteMessage("\nUDP {0} of point has a value of {1}",udpProp.Name,udpval.ToString()); tr.Commit(); } } }
Hope that helps!
What's about setting a value. If i call ent.SetUserDefinedPropertyValue( udpProp, 11); method it says about argument exception?
You must pass the argument as an object. Ammending the previous code to read, set, then read the new, looks like so:
AeccPoint ent = (AeccPoint)entRes.ObjectId.GetObject(OpenMode.ForRead).AcadObject; object udpval = ent.GetUserDefinedPropertyValue(udpProp); ed.WriteMessage("\nUDP {0} of point has a value of {1}",udpProp.Name,udpval.ToString()); object newval = "Plastic"; ent.SetUserDefinedPropertyValue(udpProp, newval); udpval = ent.GetUserDefinedPropertyValue(udpProp); ed.WriteMessage("\nUDP {0} of point now has a value of {1}", udpProp.Name, udpval.ToString());
Also, be sure the correct type for the UDP is used. In the example shown, if I tried to pass a double to the MH_Material UDP it would throw a "Parameter is iincorrect" error.
Hey @Jeff_M ,
Hoping to get some further wisdom from you here.
When I run your method from message 7, this line throws an error for me:
object udpval = ent.GetUserDefinedPropertyValue(udpProp);
The warning:
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error
at Autodesk.AECC.Interop.Land.IAeccPoint.GetUserDefinedPropertyValue(Object userDefinedProperty)
I'm not sure how to overcome this error. Any insight would be helpful.
I'm running C3D 2022, About:
Best,
~DD
@CodeDing , if you had read @Jeff_M 's reply at the beginning of the thread, you would have known that the discussion here was meant for C3D pre 2013, when no .NET API was exposed for CogoPoint's UDP data. While using COM API is still valid approach, it would lead to more potential trouble different versions of C3D. You should use .NET API CogoPoint.GetUDPValue()/SetUDPValue(), as long as you do C3D .NET plugin development.
Norman Yuan
@CodeDing as @norman.yuan noted that is some pretty old COM code. Yes, ot is still viable but the .NET API is better to use as long as this is to be run inside C3D (not a stand alone application). I believe that the error you are getting occurs when you try to get the UDP from a point which is not in a Point Group which has a UserDefined Property Classification assigned.
Thanks @norman.yuan
I'm still trying to get my head around navigating .NET, Visual Studio, and the C3D API. It's a BIG jump up from AutoLISP.
EDIT:
Thanks for getting back also Jeff
Much appreciated.
~DD
Can't find what you're looking for? Ask the community or share your knowledge.