AutoCAD Civil 3D Customization

AutoCAD Civil 3D Customization

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

getting user defined properties of a point

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

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

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.

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!

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.

*Expert Elite*
Jeff_M
Posts: 4,472
Registered: ‎07-22-2003
Message 2 of 11 (347 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 (339 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,472
Registered: ‎07-22-2003
Message 4 of 11 (336 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 (333 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 (332 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,472
Registered: ‎07-22-2003
Message 7 of 11 (312 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 (292 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 (288 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,472
Registered: ‎07-22-2003
Message 10 of 11 (284 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!