Community
Option Explicit Dim oSurfBody As SurfaceBody Dim oSurfBodies As SurfaceBodies Dim oCompDef As ComponentDefinition Dim oPartCompDef As PartComponentDefinition Dim oPartDoc As PartDocument Dim oCombFeat As CombineFeature Public Sub DeriveLeft() Dim o2CutSurfBodies As ObjectCollection Dim oRemoveSB As ObjectCollection Dim oTO As TransientObjects Set oTO = ThisApplication.TransientObjects Set o2CutSurfBodies = oTO.CreateObjectCollection Set oRemoveSB = oTO.CreateObjectCollection Set oPartDoc = ThisApplication.ActiveDocument Set oPartCompDef = oPartDoc.ComponentDefinition Set oSurfBodies = oPartCompDef.SurfaceBodies ReDim strSolidNames(oSurfBodies.Count) Dim oSBInt As SurfaceBody Dim oSBCaut As SurfaceBody For Each oSurfBody In oSurfBodies If oSurfBody.Name = "INT" Then Set oSBInt = oSurfBody ElseIf oSurfBody.Name = "CAUT" Then Set oSBCaut = oSurfBody Else Call o2CutSurfBodies.Add(oSurfBody) End If Next oSurfBody oSBInt.Visible = False oSBCaut.Visible = False Call oRemoveSB.Add(oSBInt) Call oRemoveSB.Add(oSBCaut) Dim strName As String For Each oSurfBody In o2CutSurfBodies Set oCombFeat = oPartCompDef.Features.CombineFeatures.Add _ (oSurfBody, oRemoveSB, kCutOperation, True) Next oSurfBody End Sub
When the code gets to the line performing the combine feature I can see all of my solids I need in the o2CutSurfBodies collection. As soon as the combine feature is performed there's no longer anything in the collection. Just a bunch of empty items. What am I doing wrong?
Set oPartDoc = ThisApplication.ActiveDocument Set oPartCompDef = oPartDoc.ComponentDefinition Set oSurfBodies = oPartCompDef.SurfaceBodies For Each oSurfBody In oSurfBodies 'Set oSurfBody = o2CutSurfBodies.Item(i) If oSurfBody.Name = "INT" Then 'Set oSBInt = oSurfBody ElseIf oSurfBody.Name = "CAUT" Then 'Set oSBCaut = oSurfBody Else oSurfBody.Visible = True Set oCombFeat = oPartCompDef.Features.CombineFeatures.Add _ (oSurfBody, oRemoveSB, kCutOperation, True) If Not oCombFeat.HealthStatus = 11778 Then oCombFeat.Delete End If End If Next oSurfBody
This also happens when using the surfacebodies collection. Whenever the for loop gets to the combine feature the surface bodies in oSurfBodies dissappear from the set. I don't know why.
So I've been able to get the program to work using this line
For Each oSurfBody In oPartCompDef.SurfaceBodies
instead of this line
Set oSurfBodies = oPartCompDef.SurfaceBodies For Each oSurfBody In oSurfBodies
While it works I have no idea why. Can anyone explain this to me?