Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

getting user defined properties of a point

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
aleksey.stukalov
1145 Views, 14 Replies

getting user defined properties of a point

Is there any chance to get user defined properties using .NET API for civil 2012?

14 REPLIES 14
Message 2 of 15
Jeff_M
in reply to: aleksey.stukalov

No, the CogoPoint object was not fully exposed to the .NET API until C3D2013. You can get the UDP info using the COM Interops in previous releases, however.

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 15
aleksey.stukalov
in reply to: Jeff_M

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 solutionSmiley Happy.

Message 4 of 15
Jeff_M
in reply to: aleksey.stukalov

You can get the value of a UDP for a point, just not with the .NET API. Using COM, the AeccPoint object has the GetUserDefinedPropertyValue(UDPname) method to retrieve the value.

 

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 15
aleksey.stukalov
in reply to: Jeff_M

It seems like this method GetUserDefinedPropertyValue(UDPname) doesn't work. Could you please send me working example source code?

 

Message 6 of 15
aleksey.stukalov
in reply to: Jeff_M

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.

Message 7 of 15
Jeff_M
in reply to: aleksey.stukalov

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!

Jeff_M, also a frequent Swamper
EESignature
Message 8 of 15
aleksey.stukalov
in reply to: Jeff_M

Thanx a lot! That works! I appreciate you help!

Message 9 of 15
aleksey.stukalov
in reply to: Jeff_M

What's about setting a value. If i call ent.SetUserDefinedPropertyValue( udpProp, 11); method it says about argument exception?

Message 10 of 15
Jeff_M
in reply to: aleksey.stukalov

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.

Jeff_M, also a frequent Swamper
EESignature
Message 11 of 15
aleksey.stukalov
in reply to: Jeff_M

that works! Thank you!

Message 12 of 15
CodeDing
in reply to: Jeff_M

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:

image.png

 

Best,

~DD

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 13 of 15

@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.

Message 14 of 15
Jeff_M
in reply to: CodeDing

@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.

Jeff_M, also a frequent Swamper
EESignature
Message 15 of 15
CodeDing
in reply to: norman.yuan

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

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report