By Wayne Brill
Issue
I created a ClientFeature which contains some objects. I would like to know:
How to empty the ClientFeature without deleting itself.
How to add objects to the ClientFeature again
Solution
You can use ClientFeatureElement.Delete to empty the elements in this ClientFeatureDefinition without deleting the ClientFeature. Then you can do other operations such as adding other features to the document. If you want to add or modify elements of the ClientFeature, use the ClientFeatureDefinition of the ClientFeature and add the new elements.
The following VB.NET example shows this approach. Suppose a ClientFeature has been created. Its definition contains the first extrude feature in the document. First this code removes the elements of the ClientFeature. Then adds the extrude feature again to the ClientFeature.
Note: After adding the objects, the BrowserNode position of the ClientFeature will change to that of its first element.
Sub EmptyElements(ByVal Index) Dim doc As PartDocument doc = _invApp.ActiveDocument Dim feat As ClientFeature feat = doc.ComponentDefinition _ .Features.ClientFeatures(Index) Dim featDef As ClientFeatureDefinition featDef = feat.Definition Dim elem As ClientFeatureElement For Each elem In featDef.ClientFeatureElements elem.Delete() Next End Sub Sub RedefineClientF(ByVal Index) Dim doc As PartDocument doc = _invApp.ActiveDocument Dim feat As ClientFeature feat = doc.ComponentDefinition _ .Features.ClientFeatures(Index) Dim featDef As ClientFeatureDefinition featDef = feat.Definition 'add the first extrude feature featDef.ClientFeatureElements.Add _ (doc.ComponentDefinition.Features _ .ExtrudeFeatures(1)) End Sub ' If you have not an ClientFeature ' ready for test, please refer to below ' code to create a ClientFeature: Sub createClientFeature() Dim oDoc As PartDocument = _ _invApp.ActiveDocument Dim oDef As PartComponentDefinition oDef = oDoc.ComponentDefinition Dim oClientDef As ClientFeatureDefinition oClientDef = oDef.Features. _ ClientFeatures.CreateDefinition() 'add the first extrude feature oClientDef.ClientFeatureElements.Add _ (oDef.Features.ExtrudeFeatures.Item(1)) Dim oClientFeature As ClientFeature oClientFeature = oDef.Features.ClientFeatures _ .Add(oClientDef, "My node") oClientFeature.Name = "Autodesk.com" End Sub

Leave a Reply to EscherCancel reply