Set Parcel UserDefined Property using Civil 3D API

By Partha Sarkar

One of our
valued Civil 3D customer and application developer had asked the following question:

I am trying to set the value of the existing userdefine​d
property "Address" of Parcels using the com method SetUserDefinedPropertyValue
but have had no luck…..

 

If you have the same question and looking for a solution
using the SetUserDefinedPropertyValue() API, here you go :

 

//start a transaction 
using (Transaction trans = db.TransactionManager.StartTransaction())
{
 
  //get the list of properties
  Autodesk.AECC.Interop.Land.AeccUserDefinedPropertyClassification parcelUDPClass =
      aeccDb.ParcelUserDefinedPropertyClassifications.Item(0);
 
  //get one property - create or access
  Autodesk.AECC.Interop.Land.AeccUserDefinedProperty propItem;
  if (parcelUDPClass.UserDefinedProperties.Count == 0)
  {
    //create a new property
    propItem = propItem = parcelUDPClass.UserDefinedProperties.Add("Address", "DESC",
        Autodesk.AECC.Interop.Land.AeccUDPPropertyFieldType.aeccUDPPropertyFieldTypeInteger,
        true, false, 10, true, false, 20, true, 15, null);
  }
  else
    //or access an existing one
    propItem = parcelUDPClass.UserDefinedProperties.Item(0);
 
  //apply classification changes
  aeccDb.Sites.Item(0).Parcels.Properties.SetUserDefinedPropertyClassification(
      Autodesk.AECC.Interop.Land.AeccUDPClassificationApplyWay.aeccUDPClassificationApplyAll, "Unclassified");
 
  //assuming the drawing contain at least one site, with at least one parcel
  if (aeccDb.Sites.Item(0).Parcels.Count > 0)
  {
    Autodesk.AECC.Interop.Land.AeccParcel parcel = aeccDb.Sites.Item(0).Parcels.Item(0);
    //get the property by name
    object value = parcel.GetUserDefinedPropertyValue(propItem.Name);
    //also the SET the value
    parcel.SetUserDefinedPropertyValue(propItem.Name, 13);
  }
 
  trans.Commit();
}

 

Here is the result of running the above code snippet:

 

Parcel_UDP

 

Hope this helps!


Comments

One response to “Set Parcel UserDefined Property using Civil 3D API”

  1. Thanks! Helped a lot! Couldn’t figure out why Parcel.SetUserDefinedPropertyValue was failing..

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading