4 Replies Latest reply on May 18, 2015 12:05 PM by Deepak Gupta

    Open Drawing

    David Brissenden

      Hi,

       

      What is the API function to Open a Drawing which is the equivalent of choosing Open Drawing from the right click menu of a part or assembly?

       

      Thanks

        • Re: Open Drawing
          Rolando Garza

          I'm assuming you are having trouble with your code where you can't reopen a part that is already loaded in session.

          If that is the case, take a look at the code here:

          instance a file (that is already in session) into an assembly

          • Re: Open Drawing
            Deepak Gupta

            OpenDoc6 but this would work if file is in same folder.

             

            Option Explicit

            Dim SwApp           As SldWorks.SldWorks

            Dim swModel         As SldWorks.ModelDoc2

            Dim FileName        As String

            Dim nErrors         As Long

            Dim nWarnings       As Long

             

            Sub main()

                Set SwApp = Application.SldWorks

                Set swModel = SwApp.ActiveDoc   

                FileName = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "."))

                FileName = FilePath & "slddrw"

                Set Part = SwApp.OpenDoc6(FileName, swDocDRAWING, swOpenDocOptions_Silent, "", nErrors, nWarnings)

            End Sub

              • Re: Open Drawing
                David Brissenden

                Unfortunately the drawing is not in the same folder as the part or assembly

                 

                I am programmatically opening parts and assemblies so am looking for a way to open the drawing at the same time.

                  • Re: Open Drawing
                    Deepak Gupta

                    Then try using this:

                     

                    Option Explicit

                    Dim SwApp           As SldWorks.SldWorks

                    Dim swModel         As SldWorks.ModelDoc2

                    Dim FileName        As String

                    Dim nErrors         As Long

                    Dim nWarnings       As Long

                    Const Path          As String = "C:\Test File" 'Change path here

                     

                    Sub main()

                        Set SwApp = Application.SldWorks

                        Set swModel = SwApp.ActiveDoc   

                        FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)

                        FileName = Left(FileName, InStr(FileName, "."))

                        FileName = Path & "\" & FileName & "slddrw"   

                        Set Part = SwApp.OpenDoc6(FileName, swDocDRAWING, swOpenDocOptions_Silent, "", nErrors, nWarnings) 

                    End Sub