6 Replies Latest reply on Dec 21, 2015 9:32 AM by Hrituc Alexandru

    Open assembly from selected view

    Hrituc Alexandru

      Hi everyone,

       

      I try to open assembly configuration referenced in a drawing view...

      For Models I use:

      swApp.ActivateDoc3 swView.GetReferencedModelName, swView.ReferencedConfiguration, swRebuildOnActivation_e.swUserDecision, Errors

      but for assembly doesn't work!

      It is possible that the same code to run on part and on asssembly?

      Thanks

        • Re: Open assembly from selected view
          幸 柴 田

          Hi Hrituc,

           

          I made a sample code.

          Try this.

           

          ----------------------------------------------------------------

          Option Explicit

           

           

          Sub main()

              Dim nErrors                        As Long

              Dim nWarnings                   As Long

              Dim swApp                        As SldWorks.SldWorks

              Dim swModel                     As SldWorks.ModelDoc2

              Dim swDraw                      As SldWorks.DrawingDoc

              Dim swView                       As SldWorks.View

              Dim strExt                           As String

              Dim strFileName                 As String

              Dim strConfigName                 As String

           

              Set swApp = Application.SldWorks

           

           

              Set swModel = swApp.ActiveDoc

           

           

              Set swDraw = swModel

            

              Set swView = swDraw.ActiveDrawingView

           

              strExt = UCase(Right(swView.GetReferencedModelName, 6))

             

              strFileName = swView.GetReferencedModelName

             

              strConfigName = swView.ReferencedConfiguration

             

              If strExt = "SLDPRT" Then

             

              swApp.OpenDoc6 strFileName, swDocPART, swOpenDocOptions_Silent, strConfigName, nErrors, nWarnings

              swApp.ActivateDoc2 strFileName, 1, nErrors

              Else

           

              swApp.OpenDoc6 strFileName, swDocASSEMBLY, swOpenDocOptions_Silent, strConfigName, nErrors, nWarnings

              swApp.ActivateDoc2 strFileName, 1, nErrors

              End If

           

          End Sub