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: 

Why do I get error 5 but only sometimes when trying to do splits?

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

Why do I get error 5 but only sometimes when trying to do splits?

Option Explicit
Dim blFeatChk As Boolean
Dim oWorkSurfs As WorkSurfaces
Dim oSurfBody As SurfaceBody
Dim oSurfBodies As SurfaceBodies
Dim oCompDef As ComponentDefinition
Dim oPartCompDef As PartComponentDefinition
Dim oPartDoc As PartDocument
Dim oSplitFeat As SplitFeature


Public Sub SplitAllFaces()
    Dim oInt As WorkSurface
    Dim oCaut As WorkSurface

    Set oPartDoc = ThisApplication.ActiveDocument
    Set oPartCompDef = oPartDoc.ComponentDefinition
    Set oSurfBodies = oPartCompDef.SurfaceBodies
    Set oWorkSurfs = oPartCompDef.WorkSurfaces
    
    Set oCaut = oWorkSurfs.Item("Srf1")
    Set oInt = oWorkSurfs.Item("Srf2")
    
    Dim oRS As RenderStyles
    Set oRS = oPartDoc.RenderStyles
    
    Dim oRSAL_Flat As RenderStyle
    Set oRSAL_Flat = oPartDoc.RenderStyles.Item("Aluminum - Flat")
    
    Dim oRSRed As RenderStyle
    Set oRSRed = oPartDoc.RenderStyles.Item("RED")
    
    Dim oRSBlue As RenderStyle
    Set oRSBlue = oPartDoc.RenderStyles.Item("Blue")
    
    Call SplitAllSolids(oCaut, oRSAL_Flat, oRSBlue)
    Call SplitAllSolids(oInt, oRSBlue, oRSRed)
    
    
'    For Each oSurfBody In oSurfBodies
'        lngBodyChk = 0
'        blFeatChk = True
'        Set oSplitFeat = oPartCompDef.Features.SplitFeatures.SplitBody(oInt, oSurfBody)
'
'        If blFeatChk Then
'            Set oCreatedSurfBodies = oSplitFeat.SurfaceBodies
'            For Each oCreatedSurfBody In oCreatedSurfBodies
'                If lngBodyChk = 0 Then
'                    Call oCreatedSurfBody.SetRenderStyle(kOverrideRenderStyle, oRSRed)
'                    lngBodyChk = 1
'                Else
'                    Call oCreatedSurfBody.SetRenderStyle(kOverrideRenderStyle, oRSBlue)
'                End If
'            Next oCreatedSurfBody
'        End If
'
'    Next oSurfBody
    

End Sub
Public Sub SplitAllSolids(oWorkSurf As WorkSurface, oColorIn As RenderStyle, oColorOut As RenderStyle)
    
    On Error GoTo err_SplitAllFaces
    
    Dim lngBodyChk As Long
    
    Dim oCreatedSurfBodies As SurfaceBodies
    Dim oCreatedSurfBody As SurfaceBody
    
    For Each oSurfBody In oSurfBodies
        lngBodyChk = 0
        blFeatChk = True
        Set oSplitFeat = oPartCompDef.Features.SplitFeatures.SplitBody(oWorkSurf, oSurfBody)
        
        If blFeatChk Then
            Set oCreatedSurfBodies = oSplitFeat.SurfaceBodies
            For Each oCreatedSurfBody In oCreatedSurfBodies
                If lngBodyChk = 0 Then
                    Call oCreatedSurfBody.SetRenderStyle(kOverrideRenderStyle, oColorIn)
                    lngBodyChk = 1
                Else
                    Call oCreatedSurfBody.SetRenderStyle(kOverrideRenderStyle, oColorOut)
                End If
            Next oCreatedSurfBody
        End If
        
    Next oSurfBody
    
end_SplitAllFaces:
    Exit Sub

err_SplitAllFaces:
    Select Case Err.Number
    Case -2147467259  'Place holder for no split surface
        blFeatChk = False
        Resume Next
    Case Else
      MsgBox ("Error ")
      Resume end_SplitAllFaces
    End Select
End Sub

 So for some reason and I'm not sure why the for each loop will have all the surface bodies and then sometimes not, giving me an error number 5.  Anyone know why?

 

I'm not allowed to post the model but all I'm trying for testing purpose is an array of boxes 15x100, each a seperate solid.  I have 2 surfaces that extrude through the boxes.  I'm trying to have grey, blue, and then red for each zone.  The code will work part way and then give an error.  Each time it's the for loop for surface bodies.  Sometimes the next surface body will register the next surface body and other times it won't.  I can't figure out why.

 

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

When do you observe it working? Do you open the part and perform the api? Do you run it again after the api?

 

Message 3 of 3
jpblower
in reply to: Ojdamann

I'll open the part, run the api.  Then if I delete the splits and start over I'll get part way through and then crash.

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

Post to forums  

Autodesk Design & Make Report