9 Replies Latest reply on Aug 29, 2012 7:38 PM by Alex Chen

    File name usage

    Joseph López

      Does anyone know of a VBA routine that will read the last character of a SolidWorks drawing file name? We use that last character before the ".slddrw" as our revision letter/number. I want to force two custom property fields to read and display this value to automatically update those fields in the title block. Here is the example:

       

      ####-XX-XX-###-rA.slddrw

       

      I want the custom property fields to read the character in the "A" position.

        • Re: File name useage
          Deepak Gupta

          Try this:

           

          Dim swApp As Object

          Dim swModel As Object

           

          Sub main()

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

           

          PartTitle = Right(swModel.GetTitle, InStrRev(swModel.GetTitle, " ") + 1)

           

          'Add your codes here

           

          Debug.Print "" & PartTitle

           

          End Sub

          • Re: File name usage
            Artem Taturevych

            Hello Joseph,

             

            Try this macro. It adds the last character to "Revision" property field.

             

            Dim swApp As SldWorks.SldWorks

            Dim swModel As SldWorks.ModelDoc2

             

            Const REV_FIELD As String = "Revision"

             

            Sub main()

             

                Set swApp = Application.SldWorks

               

                Set swModel = swApp.ActiveDoc

               

                Dim path As String

                path = swModel.GetPathName

               

                Dim rev As String

               

                rev = Mid(path, Len(path) - 7, 1)

               

                'try add

            swModel.Extension.CustomPropertyManager("").Add2 REV_FIELD, swCustomInfoType_e.swCustomInfoText, rev

               

            swModel.Extension.CustomPropertyManager("").Set REV_FIELD, rev

             

            End Sub

            ______________________

            Artem Taturevych

            Application Engineer at Intercad

            http://intercad.com.au/

            Tel: +61 2 9454 4444

            • Re: File name usage
              Alex Chen

              Hi, Joe:

               

              I want to give you the following feedbacks (all negative, LOL) on the approach you are using:

               

              1) To include revision info in file name is like someone to tattoo his/her body with age.

              2) If you need to link two custom properties to a revision, then there is a redundancy issue.

              3) If you do want to put revision info in both file name and two custom properties, you need to make sure that their correct relationship (parent-child).

              4) When you save a drawing document, it is not always true that you want to bump revision of a document.

               

              Something for you to think about.

               

              Best regards,

               

              Alex