1 Reply Latest reply on Jul 28, 2017 1:06 PM by Deepak Gupta

    Macro - Get File Name Stripped Down in Drawing File

    Nick Maddox

      Hello all,

      My goal is to take a drawing file name and split it into two fields (the first 18 characters in the "number" custom property, the rest will be in a "description" field.


      I have a working macro, but it adds the sheet title at the end of the "description" field.  Any ideas how to remove it?



      Or is there a way of using the $PRP:"SW-File Name" to get a "clean" file name for me to use?


      Thanks in advance,


        • Re: Macro - Get File Name Stripped Down in Drawing File
          Deepak Gupta

          There are two ways:


          1. Use swmodel.GetPathname and remove everything from it except for file name and then use that further.


          2. Strip sheet name from the file name first and then use.


          Here is an example for both options


          Option Explicit
          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          Dim sFileName As String
          Sub Main()
          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          ' Option 1
          sFileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)
          sFileName = Left(sFileName, InStrRev(sFileName, ".") - 1)
          Debug.Print sFileName
          ' Option 2
          sFileName = Left(swModel.GetTitle, Len(swModel.GetTitle) - Len(swModel.GetCurrentSheet.GetName) - 3)
          Debug.Print sFileName
          End Sub