2 Replies Latest reply on Jan 7, 2016 5:19 AM by Amen Allah Jlili

    Open folder containing the part with the selected face

    Tim Lewis

      I would like to be able to use a macro to open the folder containing the part that the selected face belongs to.  Currently, I can open the folder containing a selected part (i.e. the entire part is selected from the feature tree) with the following code:

       

      Sub OpenDir()

          Dim selMgr As SelectionMgr, Path As String

        

          With Application.SldWorks.ActiveDoc

              Path = .GetPathName

            

              With .SelectionManager

                  If .GetSelectedObjectCount2(-1) <> 0 And _

                     .GetSelectedObjectType3(1, -1) <> 0 Then

                      Path = .GetSelectedObject6(1, -1).GetPathName

                  End If

              End With

          End With

        

          Shell "explorer.exe """ & Left(Path, Len(Path) - 20) & """", vbNormalFocus

      End Sub

       

      I thought I could get the path of the part containing the selected face by using one of the following in place of the code on Line #10:

       

      Path = .GetSelectedObject6(1, -1).GetBody.GetPathName

       

       

      or

       

      Path = .GetSelectedObject6(1, -1).GetModelDoc.GetPathName

       

      In other words, get the path to the file that contains the selected face.  However, both commands produce the following error:

       

      Screenshot_1.png

       

      Can anyone tell me what I'm doing wrong?