AutoCAD Civil 3D Customization

Reply
Contributor
aleksey.stukalov
Posts: 14
Registered: ‎02-27-2012
Message 1 of 11 (330 Views)
Accepted Solution

getting user defined properties of a point

330 Views, 10 Replies
12-10-2012 04:40 AM

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

*Expert Elite*
Jeff_M
Posts: 4,227
Registered: ‎07-22-2003
Message 2 of 11 (324 Views)

Re: getting user defined properties of a point

12-10-2012 06:22 AM 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
Contributor
aleksey.stukalov
Posts: 14
Registered: ‎02-27-2012
Message 3 of 11 (316 Views)

Re: getting user defined properties of a point

12-10-2012 08:13 PM 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 solution:smileyhappy:.

*Expert Elite*
Jeff_M
Posts: 4,227
Registered: ‎07-22-2003
Message 4 of 11 (313 Views)

Re: getting user defined properties of a point

12-10-2012 08:25 PM 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
Contributor
aleksey.stukalov
Posts: 14
Registered: ‎02-27-2012
Message 5 of 11 (310 Views)

Re: getting user defined properties of a point

12-10-2012 08:29 PM in reply to: Jeff_M

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

 

Contributor
aleksey.stukalov
Posts: 14
Registered: ‎02-27-2012
Message 6 of 11 (309 Views)

Re: getting user defined properties of a point

12-10-2012 08:32 PM 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.

*Expert Elite*
Jeff_M
Posts: 4,227
Registered: ‎07-22-2003
Message 7 of 11 (289 Views)

Re: getting user defined properties of a point

12-11-2012 03:42 PM 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
Contributor
aleksey.stukalov
Posts: 14
Registered: ‎02-27-2012
Message 8 of 11 (269 Views)

Re: getting user defined properties of a point

12-13-2012 11:49 PM in reply to: Jeff_M

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

Contributor
aleksey.stukalov
Posts: 14
Registered: ‎02-27-2012
Message 9 of 11 (265 Views)

Re: getting user defined properties of a point

12-14-2012 12:53 AM in reply to: Jeff_M

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

*Expert Elite*
Jeff_M
Posts: 4,227
Registered: ‎07-22-2003
Message 10 of 11 (261 Views)

Re: getting user defined properties of a point

12-14-2012 06:17 AM 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Civil 3D Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for AutoCAD Civil 3D helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Civil 3D

Twitter

Facebook

Blogs