Probably a silly macro question with a simple answer
Probably a silly macro question with a simple answer
(OP)
I'm sure this problem has a simple solution, I just don't write code, hence:
The code below *works* but I am looking for something a bit more elegant. Basically the macro runs through the custom properties to see what revision the drawing is on. The property that decides the revision is named "REVISION A" or B, or C, etc. and the value is "AA", "AB", etc. (no quotes for any).
I want the macro to output a string that represents the most recent revision, for example "-AF".
How would you make this code simpler?
The code below *works* but I am looking for something a bit more elegant. Basically the macro runs through the custom properties to see what revision the drawing is on. The property that decides the revision is named "REVISION A" or B, or C, etc. and the value is "AA", "AB", etc. (no quotes for any).
I want the macro to output a string that represents the most recent revision, for example "-AF".
How would you make this code simpler?
CODE -->
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim ext As String
Dim revA As String
Dim revB As String
Dim revC As String
Dim revD As String
Dim revE As String
Dim revF As String
Dim revG As String
Dim revH As String
Dim revI As String
Dim revJ As String
Dim revK As String
Dim revL As String
Dim revM As String
Dim revN As String
Dim revO As String
Dim revP As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'Grabs potential revision level
revA = swModel.GetCustomInfoValue("", "REVISION A")
revB = swModel.GetCustomInfoValue("", "REVISION B")
revC = swModel.GetCustomInfoValue("", "REVISION C")
revD = swModel.GetCustomInfoValue("", "REVISION D")
revE = swModel.GetCustomInfoValue("", "REVISION E")
revF = swModel.GetCustomInfoValue("", "REVISION F")
revG = swModel.GetCustomInfoValue("", "REVISION G")
revH = swModel.GetCustomInfoValue("", "REVISION H")
revI = swModel.GetCustomInfoValue("", "REVISION I")
revJ = swModel.GetCustomInfoValue("", "REVISION J")
revK = swModel.GetCustomInfoValue("", "REVISION K")
revL = swModel.GetCustomInfoValue("", "REVISION L")
revM = swModel.GetCustomInfoValue("", "REVISION M")
revN = swModel.GetCustomInfoValue("", "REVISION N")
revO = swModel.GetCustomInfoValue("", "REVISION O")
revP = swModel.GetCustomInfoValue("", "REVISION P")
If revP = "AP" Then
ext = "-AP"
ElseIf revO = "AO" Then
ext = "-AO"
ElseIf revN = "AN" Then
ext = "-AN"
ElseIf revM = "AM" Then
ext = "-AM"
ElseIf revL = "AL" Then
ext = "-AL"
ElseIf revK = "AK" Then
ext = "-AK"
ElseIf revJ = "AJ" Then
ext = "-AJ"
ElseIf revI = "AI" Then
ext = "-AI"
ElseIf revH = "AH" Then
ext = "-AH"
ElseIf revG = "AG" Then
ext = "-AG"
ElseIf revF = "AF" Then
ext = "-AF"
ElseIf revE = "AE" Then
ext = "-AE"
ElseIf revD = "AD" Then
ext = "-AD"
ElseIf revC = "AC" Then
ext = "-AC"
ElseIf revB = "AB" Then
ext = "-AB"
ElseIf revA = "AA" Then
ext = "-AA"
End If
End Sub 





RE: Probably a silly macro question with a simple answer
CODE --> English
Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swCustPropMgr As SldWorks.CustomPropertyManager Dim nNbrProps As Long Dim i As Long Dim vPropNames As Variant Dim valOut As String Dim resolvedValOut As String Dim ext As String Sub main() Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swCustPropMgr = swModel.Extension.CustomPropertyManager("") nNbrProps = swCustPropMgr.Count vPropNames = swCustPropMgr.GetNames For i = 0 To nNbrProps - 1 swCustPropMgr.Get2 vPropNames(j), valOut, resolvedValOut If InStr(vPropNames(j), "Revision") Then ext = "-" & valOut Debug.Print "" & ext End If Next i End SubDeepak Gupta
CSWE, CSWP, CSDA
SW 2012 SP4.0 & 2013 PR1
Boxer's SolidWorks™ Blog
SolidWorks™ Rendering Contest
RE: Probably a silly macro question with a simple answer
I changed part of the For statement to better select what I needed. Also, I think some of the j's were supposed to be i's in your code, at least that worked for me.
CODE
For i = 0 To nNbrProps - 1 swCustPropMgr.Get2 vPropNames(i), valOut, resolvedValOut If InStr(vPropNames(i), "REVISION") And valOut <> "" Then rev = "-" & valOut End If Next iRE: Probably a silly macro question with a simple answer
Deepak Gupta
CSWE, CSWP, CSDA
SW 2012 SP4.0 & 2013 PR1
Boxer's SolidWorks™ Blog
SolidWorks™ Rendering Contest