AnsweredAssumed Answered

API to get specific digit from file name.

Question asked by jason kooken on Apr 7, 2016
Latest reply on Jul 1, 2016 by Solid Air

I have a part numbering system that has the drawing rev built into the filename for example: 11111234A-PM.slddrw

Previously the Macro used to save this drawing would get the revision from custom properties.

This field is no longer updated and there is now a need to retrieve the revision from the filename instead.


Below is a clip of the current macro, in the "get revision" section is what was used to get the rev, I want to get the revision from the 9th digit of the file name as "rev"

any help would be greatly appreciated.


Dim longstatus As Long, longwarnings As Long

Dim swModel As SldWorks.ModelDoc2

Dim swApp As SldWorks.SldWorks



Sub main()

    Set swApp = Application.SldWorks

    Set Part = swApp.ActiveDoc

    Set swModel = swApp.ActiveDoc

    Set SelMgr = Part.SelectionManager

    Dim proj As String

    Dim dwg As String

    Dim filename As String

    Dim saveLoc As String

    Dim lastTwoChar As String

    Dim rev As String

    Dim trueRev As String

    Set swCusPropMgr = swModel.Extension.CustomPropertyManager("")



    filename = swModel.GetPathName

    If filename = "" Then

        MsgBox "Please save the file first and try again", vbCritical


    End If



    'Get Revision

    retval = swCusPropMgr.Get3("Revision", False, rev, trueRev)

    If rev = "-" Then

        rev = "-"

    End If