MACRO LIBRARY

Lesson 3.1 homework part B solution

Free public access. No account or subscription required.

Files

Lesson 3.1 homework part B solution

Code

'Homework 3.1
'Create a macro that switches the current part document (which is already saved to the _
    hard-drive) to isometric, zooms to fit, turns on shaded with edges, then saves and _
    closes the document. _
    Note 1: Changing display settings uses an interface not discussed in the lesson video. _
    However, with what you know thus far you should know how to look up this interface and _
    determine which members to use. _
    Note 2: When the close the document, pay attention to whether your Windows folder options _
    are set to show file extensions.
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelView As SldWorks.ModelView
Dim lngErrors As Long
Dim lngWarnings As Long
Dim strTitle As String
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swModelView = swModel.ActiveView
    
    swModel.ShowNamedView2 "", 7
    swModel.ViewZoomtofit2
    swModelView.DisplayMode = swViewDisplayMode_ShadedWithEdges
    swModel.Save3 0, lngErrors, lngWarnings
    
    'The following code will ensure that the proper document title is always found for use _
        with ISldWorks::CloseDoc, regardless of the Windows folder options
    strTitle = UCase(swModel.GetTitle)
    If InStr(1, swModel.GetTitle, ".SLDPRT") <> 0 Then
        swApp.CloseDoc swModel.GetTitle
    Else
        swApp.CloseDoc Right(swModel.GetPathName, Len(swModel.GetTitle) + 7)
    End If
End Sub