7 Replies Latest reply on Jun 6, 2017 2:42 PM by John Alexander

    GetVisibleEntities causes crash when type is swViewEntityType_SilhouetteEdge

    John Alexander

      Good morning,

       

      I'm working on a SW2012 VBA macro for inserting machine marks on prints automatically. In our current workflow, the designers color machined surfaces white in the Parts. I modified our face colorizing macro so that an attribute is added to the Face. When the active document is a drawing, the macro traverses all views, deduces which visible edges are bounding a face that has been marked for machining, and excludes faces that aren't perpendicular to the view's "camera axis", and inserts the appropriate nabla symbol.

       

      Thus far, it works fine for simple planar faces but curved faces are causing trouble.

       

      I believe I've narrowed it down to the following call.

      vVisibleEntities = swView.GetVisibleEntities(vVisibleComponents(0), swViewEntityType_e.swViewEntityType_SilhouetteEdge)

      When the macro executes, I observe the silhouette edges being selected in rapid succession and then it crashes.

       

       

      There are no explicit calls to select any silhouette edges in this macro. When the above line is commented out, the macro performs as usual but does not consider the silhouette edges of that cylindrical surface depicted above.

       

      Has anyone encountered this before with silhouette edges on drawings? This is an annoying thing to troubleshoot as my VBA editor has to close every time I get it wrong.

       

      For context, the following function is where the troublesome call is made.

      Private Function getVisibleSilhouetteEdge(swFace As SldWorks.Face2, swView As SldWorks.View) As SldWorks.SilhouetteEdge

          Dim newFace                 As SldWorks.Face2

          Dim swVisibleEntity         As SldWorks.Entity

          Dim swVisibleSilhouetteEdge As SldWorks.SilhouetteEdge

          Dim vVisibleEntities        As Variant

          Dim vVisibleEntity          As Variant

          Dim vVisibleComponents      As Variant

          Dim oldID As Integer

          Dim newID As Integer

         

         

          vVisibleComponents = swView.GetVisibleComponents()

          If Not (vVisibleComponents(0) Is Nothing) Then

              vVisibleEntities = swView.GetVisibleEntities(vVisibleComponents(0), swViewEntityType_e.swViewEntityType_SilhouetteEdge)

              If IsArrayAllocated(vVisibleEntities) Then

                  For Each vVisibleEntity In vVisibleEntities

                      Set swVisibleEntity = vVisibleEntity

                     

                      Set newFace = swVisibleSilhouetteEdge.GetFace

                      If swFace Is newFace Then

                          Set getVisibleSilhouetteEdge = swVisibleSilhouetteEdge

                          Exit For

                      End If

                  Next vVisibleEntity

              End If

          End If

      End Function