Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Object collection clears whenever I use the combine feature

2 REPLIES 2
Reply
Message 1 of 3
jpblower
300 Views, 2 Replies

Object collection clears whenever I use the combine feature

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?

2 REPLIES 2
Message 2 of 3
jpblower
in reply to: jpblower

        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.

Message 3 of 3
jpblower
in reply to: jpblower

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?

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report