AnsweredAssumed Answered

How Do You Select and Open Files in Design Binder Using API

Question asked by Jonathan Sterling on Jun 14, 2017
Latest reply on May 23, 2018 by Wayne Matus

Hi all,

 

I have searched the forums here and external to this site trying to find any examples or discussions about the above topic to no avail.

 

First, what I am trying to do is create a macro (vba) that will open a specifically named document we place in our SW files in the Design Binder.

 

Second, the two avenues I went down was first to try doing a record to find what SW suggested which returns the following:

 

     Dim swApp As Object

     Dim Part As Object

     Dim boolstatus As Boolean

     Dim longstatus As Long, longwarnings As Long

     Sub main()

          Set swApp = Application.SldWorks

          Set Part = swApp.ActiveDoc

          boolstatus = Part.Extension.SelectByID2("Design Journal.doc", "JOURNAL", 0, 0, 0, False, 0, Nothing, 0)

     End Sub

 

This unfortunately doesn't work at selecting the file, that's when I began digging leading to the second code I was able to piece together based on the runcommand:

 

 

     Dim swApp As SldWorks.SldWorks

     Dim swModel As SldWorks.ModelDoc2

     Dim swModExt As SldWorks.ModelDocExtension

     Dim boolstatus As Boolean

     'Dim swComm As swCommand_e

     'Dim pmpTitle As String

     'Dim commandID As Long

     Sub main()

          boolstatus = False

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

          Set swModExt = swModel.Extension

          boolstatus = swModExt.RunCommand(swCommands_Activate_Doc_Or_Journal, "")

     End Sub

 

This will open the file, but only if you select it in the feature tree first. So now I am back to square one of how to select the file in the feature tree. Any help or insight would be greatly appreciated.

 

Thanks

Outcomes