I am trying to use Civil 3D .NET API to set the Pipe Object's PartDataField e.g. Pipe's Manning Coefficient. Could you help me with a code snippet to do this?
Civil 3D .NET API allows us to set / edit the PartDataField value. First you need to open the Part (Pipe or Structure) for write, get a reference to the Part object's PartData property (type PartDataRecord), modify the PartDatafield value, and then re-set the Part's PartData.
Here is a C# code snippet which demonstrates updating Pipe's Part Data values (Manning Coefficient):
using (Transaction ts = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
{
Pipe PipeEle = ts.GetObject(pipeID, OpenMode.ForWrite) as Pipe;
PartDataRecord record = PipeEle.PartData;
PartDataField PartDataFld = record.GetDataFieldBy(PartContextType.FlowAnalysisManning);
ed.WriteMessage("\nManning Coefficient Value Before Change : " + PartDataFld.Value.ToString());
// Change the inner data of the copy:
PartDataFld.Value = 0.014;
// Re-set the PartData property.
//The data will not be updated without this
PipeEle.PartData = record;
ed.WriteMessage("\nManning Coefficient Value After Change : " + PartDataFld.Value.ToString());
ts.Commit();
}