1 Reply Latest reply on Apr 27, 2017 11:31 PM by Deepak Gupta

    Click on a part in design tree and then get file name using macros

    Marco Wu

      I want to extract a part file name from an assembly by clicking the part in the assembly tree

      I have recorded a macro, but I am not sure how to get the extract file name from the macro. Please see the attachment

        • Re: Click on a part in design tree and then get file name using macros
          Deepak Gupta

          Try these codes

           

          Option Explicit
              Dim swApp               As SldWorks.SldWorks
              Dim swModel             As SldWorks.ModelDoc2
              Dim swSelMgr            As SelectionMgr
              Dim selComp             As Component2
              Dim sPath               As String
          Sub Main()
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set swSelMgr = swModel.SelectionManager
                  
              Set selComp = swSelMgr.GetSelectedObjectsComponent4(1, -1)
              sPath = Strings.Mid(selComp.GetPathName, InStrRev(selComp.GetPathName, "\") + 1)
              sPath = Left(sPath, InStrRev(sPath, ".") - 1)
                  
              MsgBox sPath
          End Sub