×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Probably a silly macro question with a simple answer

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?

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

Try this

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 Sub 

Deepak 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

(OP)
Thanks Deepak,

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 i 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources