Hi,
I wonder if it's possible to add custom made properties to pipes and structures in civil3D through the .NET API?
How would I do that?
Thanks
Solved! Go to Solution.
Solved by tyronebk. Go to Solution.
I really hope I'm wrong, but I don't think it's possible to create new custom pipe and structure properties through the .Net API. However, once the custom properties are available in the part you can change their values with the API (look into the PartDataRecord and PartDataField classes).
Hi,
Does Civil 3D UI tools allows us to add custom properties to Pipes and Structures ?
I am asking this to confirm that I am not missing anything obvious here.
How about using Xdata / Xrecord (though I haven't tried them on Civil 3D Pipes and Structures) ?
Thanks,
Partha
Xdata/Xrecord may work for some cases but misses out on the ability to be called out in Civil 3D labels. After a bit more searching it looks like .net cannot yet add custom properties (there is a bit of .net code on this page for retrieving properties). I haven't yet tested it but you may be able to invoke the PartDataRecord.append COM method to add custom properties. See the relevant COM code here.
In the past I added custom properties by editing the XML files as shown on Being Civil. Unlike parcels or points, it doesn't seem to be possible to add custom properties through the UI.
Thanks for the update.
You could check one of my earlier post in IM DevBlog :
This link says : Dynamic properties created with the NetworkCatalogDef class are not yet supported by the .NET API.
Let me know if you succedd in using the COM API or you need any further help from me.
Thanks,
Partha
Thanks for your inputs!
Actually tyronebk, I managed to add custom parameters to custom parts just as Being Civil suggests. The problem is that adding those parameters via XML doesn't mean I can access them through .NET, right?
After some further research, I wonder: can't I use an extension method to the pipe class in order to create a sub or a function with the pipe object?
I'm still trying to find out what's the best way to go...
No, you can actually access and change those custom properties, you just can't create them in .net. Here are a couple of methods I've used to get or set the custom property values.
private string GetPartOtherProperty( Part part, string propertyName ) { return part.PartData.GetDataFieldBy( propertyName ).Value.ToString(); } private bool SetPartOtherProperty( Part part, string propertyName, string val ) { PartDataField pdf = part.PartData.GetDataFieldBy( propertyName ); if ( !pdf.IsReadOnly ) { pdf.Value = val; return true; }
else return false; }
Thanks for your input!
So how do you create the properties? Is it through XML files?
My problem is that even though I created the parameter and the parameter now appears in the Part Data Structure Properties in civil3D, I can't access it through part.PartData.GetDataFieldBy. When I try this, my new parameter doesn't appear listed...
WOW! This is great!
I tried your method and it works. Even though it's not listed, if I type the property name in getdatafieldby function I get the value of the custom parameter created!
Thanks a lot! That made my day!
Good Afternoon,
I really appreciate you posting your code tyronebk! I have just started venturing into .net from writing in AutoLisp and its a bit intimidating. Do you have any suggestions of where I can find sample code I can plug your code into so I can create a program that allows the user to change the custom property of all the selected pipes?
Thank you,
Eric
<CommandMethod("KLTestCommandGroup", "AddDPToPipe", CommandFlags.Modal)> _ Public Sub AddDynamicPropertyToPipe() Dim ed As Autodesk.AutoCAD.EditorInput.Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim SelectedPipe As AeccPipe = C3DUtil.SelectPipe() If Not SelectedPipe Is Nothing Then If Not TestFunctions.DeclareNewParameterToPipeNetworkCatalog(C3DUtils, _ "KLDesign", "KLDesign", "TypeDimension", "Type and Dimension united", _ AeccPartDataFieldType.aeccString, AeccPipeNetworkUsage.aeccStringGeneral) Then Return End If Dim oPartDataField As AeccPartDataField = Nothing Try oPartDataField = SelectedPipe.PartDataRecord.FindByContextAndIndex("KLDesign", 0) Catch exArg As System.ArgumentException Debug.WriteLine("Argument Exception: " + exArg.Message + "(" + exArg.ParamName + ")") Catch ex As Exception ed.WriteMessage(vbLf + "Virhe: " + ex.Message) End Try If oPartDataField Is Nothing Then oPartDataField = SelectedPipe.PartDataRecord.Append("KLDesign", 0) 'oPartDataField.Tag = "Testi 2Mpuk / DN40" End If End Sub
Public Shared Function DeclareNewParameterToPipeNetworkCatalog(ByRef C3DUtils As C3DUtilities.C3DUtil, _ ByVal GlobalContext As String, ByVal DisplayContext As String, ByVal ParamName As String, _ ByVal ParamDesc As String, ByVal DataType As Autodesk.AECC.Interop.Pipe.AeccPartDataFieldType, _ ByVal Usage As Autodesk.AECC.Interop.Pipe.AeccPipeNetworkUsage) As Boolean If C3DUtils Is Nothing Then Return False Try Dim oSettings As AeccPipeSettingsRoot = C3DUtils.PipeAeccDoc.Settings Dim oPipeNetworkCatDef As AeccPipeNetworkCatDef = oSettings.PipeNetworkCatDef oPipeNetworkCatDef.DeclareNewParameter(GlobalContext, DisplayContext, ParamName, ParamDesc, DataType, Usage, "Meters", True, False) oPipeNetworkCatDef.DeclarePartProperty(GlobalContext, AeccPipeNetworkDomain.aeccDomPipe, 10) Catch ComEx As System.Runtime.InteropServices.COMException If ComEx.ErrorCode = -2145386475 Then 'Duplicate key Return True End If End Try Return True End Function
Have anyone try to create properties like above code? I don´t remember is this work because it was about Civil 2010 version when I try to figure this out but smothing maybe missing.
Cheers
Veli V.