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:
Can anyone tell me what I'm doing wrong?
SolidworksApi macros