MACRO LIBRARY

Lesson 2.3 homework part A solution

Free public access. No account or subscription required.

Files

Lesson 2.3 homework part A solution

Code

'Homework 2.3a
'Create a macro that displays a SolidWorks message box stating what license type _
    (i.e., full, educational, student) was used when the model was created. Include _
    error handling in the even that the user runs the macro without a model open.
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    If Not swModel Is Nothing Then
        Debug.Print swModel.Extension.GetLicenseType
        Select Case swModel.Extension.GetLicenseType
            Case 0
                swApp.SendMsgToUser2 "License type: Full", swMbWarning, swMbOk
            Case 1
                swApp.SendMsgToUser2 "License type: Educational", swMbWarning, swMbOk
            Case 2
                swApp.SendMsgToUser2 "License type: Student", swMbWarning, swMbOk
            Case 3
                swApp.SendMsgToUser2 "License type: Student Design Kit", swMbWarning, swMbOk
            Case 4
                swApp.SendMsgToUser2 "License type: Personal", swMbWarning, swMbOk
        End Select
    Else
        swApp.SendMsgToUser2 "Please open a document.", swMbWarning, swMbOk
    End If
End Sub