Issue
How can I create a sculpt feature programmatically?
The following is a sample illustrating the way of creating a sculpt feature.
Please download the attached sample file before running the code: Download part model
VB .NET sample code:
Sub RunSculptDemo()
'reference to the part document
Dim oDoc As PartDocument _
= TryCast(oApp.ActiveDocument, PartDocument)
If oDoc Is Nothing Then Exit Sub
Dim oDef As PartComponentDefinition _
= oDoc.ComponentDefinition
'features collection
Dim oFeatures As PartFeatures = oDef.Features
'surfaces collection
Dim oSurfaces As ObjectCollection = _
oApp.TransientObjects.CreateObjectCollection()
For Each osurface As WorkSurface In oDef.WorkSurfaces
oSurfaces.Add(oFeatures.SculptFeatures _
.CreateSculptSurface(osurface, _
PartFeatureExtentDirectionEnum.kNegativeExtentDirection))
Next
'create sculpt feature
Dim oSculpt As SculptFeature = oFeatures _
.SculptFeatures.Add(oSurfaces, _
PartFeatureOperationEnum.kCutOperation)
End Sub
C# sample code:
void RunSculptDemo()
{
//get reference to active part document
PartDocument oDoc = (PartDocument)oApp.ActiveDocument;
PartComponentDefinition oDef = oDoc.ComponentDefinition;
//features collection
PartFeatures oFeatures = oDef.Features;
//surfaces collection
ObjectCollection oSurfaces =
oApp.TransientObjects.CreateObjectCollection();
foreach (WorkSurface osurface in oDef.WorkSurfaces)
{
oSurfaces.Add(oFeatures.SculptFeatures
.CreateSculptSurface(osurface,
PartFeatureExtentDirectionEnum.kNegativeExtentDirection));
}
//create sculpt feature
SculptFeature oSculpt = oFeatures
.SculptFeatures.Add(oSurfaces,
PartFeatureOperationEnum.kCutOperation);
}
VBA sample code:
Sub RunSculptDemo()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition
Set oDef = oDoc.ComponentDefinition
Dim oFeas As PartFeatures
Set oFeas = oDef.Features
Dim oSurfaces As ObjectCollection
Set oSurfaces = ThisApplication _
.TransientObjects.CreateObjectCollection
Dim osurface As WorkSurface
For Each osurface In oDef.WorkSurfaces
oSurfaces.Add oFeas.SculptFeatures _
.CreateSculptSurface(osurface, _
kNegativeExtentDirection)
Next
Dim oSculpt As SculptFeature
Set oSculpt = oFeas.SculptFeatures _
.Add(oSurfaces, kCutOperation)
End Sub