I am cutting a part in such a way that it creates two bodies (parent conf). I need to store each of these bodies in their own configuration (children conf). How can I delete one body for each configuration?
I tried the following three methods, but the parent and children configurations all have the same features with what I tried (both bodies deleted in all configurations). Code attached.
1. swModel.ShowConfiguration2()
2. swConf.Select (False) 'Selects only the current configuration
3. swModel.FeatureManager.InsertDeleteBody.SetSuppression2 swSuppressFeature, swAllConfiguration, Empty
What you're doing is similar because the problem is solved by having the correct configuration active when a feature is created or its suppression state modified. You don't need to get the "Suppress new features" option involved.
Your problem statement isn't clear as to whether you want one body suppressed or unsuppressed per configuration, but I am going to assume the latter.
===
'For each body in the part, create a configuration that contains only that body. _
All other bodies are suppressed.
'Precondition: part is open
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim swFeat As SldWorks.Feature
Dim swConfig As SldWorks.Configuration
Dim vBodies As Variant
Dim i As Integer, j As Integer
Dim strOriginalConfigName As String
Dim colConfigName As New Collection
Dim colDeleteBodyName As New Collection
Sub main()
Set colConfigName = Nothing
Set colDeleteBodyName = Nothing
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
strOriginalConfigName = swModel.ConfigurationManager.ActiveConfiguration.Name
Set swPart = swModel
vBodies = swPart.GetBodies2(swAllBodies, False)
If IsEmpty(vBodies) Then Exit Sub
For i = 0 To UBound(vBodies)
Set swConfig = swModel.AddConfiguration3(vBodies(i).Name, Empty, Empty, Empty)
colConfigName.Add swConfig.Name
swModel.Extension.SelectByID2 vBodies(i).Name, "SOLIDBODY", 0, 0, 0, False, 0, Nothing, 0
Set swFeat = swModel.FeatureManager.InsertDeleteBody
colDeleteBodyName.Add swFeat.Name
Next i
For i = 1 To colConfigName.Count
swModel.ShowConfiguration2 colConfigName.Item(i)
For j = 1 To colDeleteBodyName.Count
Set swFeat = swPart.FeatureByName(colDeleteBodyName.Item(j))
If j = i Then
swFeat.SetSuppression2 swSuppressFeature, swThisConfiguration, Empty
Else
swFeat.SetSuppression2 swUnSuppressFeature, swThisConfiguration, Empty
End If
Next j
Next i
swModel.ShowConfiguration2 strOriginalConfigName
End Sub
===
Keith
SolidWorks API Video Tutorials