3 Replies Latest reply on Jan 9, 2015 4:48 PM by Mark Olsen

    API call equivalent to "Show All Envelopes"

    Mark Olsen

      Is there an API call that is the same as the 'Show All Envelopes' command in an assembly?  (RMB on a subassembly, about 3/4 of the way down)  I've looked all over, but I can't find one.

        • Re: API call equivalent to "Show All Envelopes"
          Keith Rice

          Mark,

           

          There is no such API call, but this can still be accomplished fairly easily. You would simply traverse all components and see if the component is an envelope using IComponent2::IsEnvelope. If yes, then show it.

           

          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          Dim swAssy As SldWorks.AssemblyDoc
          Dim swComp As SldWorks.Component2
          Dim i As Integer
          Dim vComps As Variant
          
          Sub main()
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set swAssy = swModel
              vComps = swAssy.GetComponents(False)
              For i = 0 To UBound(vComps)
                  Set swComp = vComps(i)
                  If swComp.IsEnvelope Then swComp.Visible = swComponentVisible
              Next i
          End Sub
          

           

          Keith

          SolidWorks API Tutorials

            • Re: API call equivalent to "Show All Envelopes"
              Mark Olsen

              That's what I've started to do, but I thought that it'd be better to not re-invent the wheel if the call was already there.  What you posted gives me some ideas, though.  What I want to show is envelopes in selected sub-assemblies.

               

              Thanks for the reply,

              Mark

              • Re: API call equivalent to "Show All Envelopes"
                Mark Olsen

                Keith,

                     Ok, everything works except for making the envelope visible.  I have tested, and it selects the subcomponents, and correctly checks if they are an envelope, but they just don't become visible.

                 

                Dim swApp As SldWorks.SldWorks
                Dim swPart As SldWorks.ModelDoc2
                Dim swSelMgr As SelectionMgr
                Dim myComp As Object
                Dim mySubPart As Object
                Dim boolstatus As Boolean
                Dim c As Integer
                Dim i As Integer

                Sub main()

                Set swApp = Application.SldWorks
                Set swPart = swApp.ActiveDoc
                Set swSelMgr = swPart.SelectionManager
                c = swSelMgr.GetSelectedObjectCount

                           
                For i = 1 To c
                    Set myComp = swSelMgr.GetSelectedObject6(i, -1)
                    Set mySubPart = myComp.GetModelDoc2
                    If mySubPart.GetType = 2 Then
                   
                            Dim swSubAssy As SldWorks.AssemblyDoc
                            Dim vComps As Variant
                            Dim swComp As SldWorks.Component2
                            Dim j As Integer
                           
                            Set swSubAssy = mySubPart
                            vComps = swSubAssy.GetComponents(False)
                            For j = 0 To UBound(vComps)
                                Set swComp = vComps(j)
                                If swComp.IsEnvelope Then swComp.Visible = True
                            Next
                    End If
                Next

                End Sub