Code pasted in below.
Macro set for SolidWorks default Hotkey setting: Front View = + 1 Back View = + 2 Left View = + 3 Right View = + 4 Top View = + 5 Bottom View = + 6 Iso View = + 7
If your's is setup different, go to this section and change the values. 'Default SW - Key-string for model views
Enjoy, Ken
********* Code Below ********* 'NOTE: ' Macro does not behave right when running from within VB. ' Call/Run macro directly from SolidWorks, otherwise the SendKeys function sends the keys to VB.
'Started From SW API Help Example: 'Change to Isometric and Zoom to Fit View Mode Example (VB) 'This example shows how to change the current view mode to isometric and Zoom to Fit. '----------------------------------------------- ' ' Preconditions: Model document is open. ' ' Postconditions: Current view mode is changed. ' '-----------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2
Sub Pause(PauseTime As Double) 'VBA Example: 'Timer Function Example 'This example uses the Timer function to pause the application. The example also uses DoEvents to yield to other processes during the pause.
Dim Start As Double Dim Finish As Double Dim TotalTime As Double
Start = Timer ' Set start time. Do While Timer < Start + PauseTime DoEvents ' Yield to other processes. Loop Finish = Timer ' Set end time. TotalTime = Finish - Start ' Calculate total time. 'MsgBox "Paused for " & TotalTime & " seconds"
End Sub
Sub TransitionView_CommonOps() 'Zoom to extents 'swModel.ViewZoomtofit2
Pause 1 End Sub
'This Module For Reference Only...I don't like the way the views change. ' They don't "animate" when they move. ' They need to be Zoomed to Extents. Sub v01_main()
Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc
If (swModel Is Nothing) Then MsgBox "No SolidWorks document open." & Chr(13) & "Routine ending.", vbCritical, "ModelView Rotation" End End If
If (swModel.GetType swDocDRAWING) Then
'Set view 'swModel.ShowNamedView2 "*Isometric", 7 'swModel.ShowNamedView2 "*Trimetric", 8 swModel.ShowNamedView2 "*Dimetric", 9 Call TransitionView_CommonOps
swModel.ShowNamedView2 "*Front", -1 Call TransitionView_CommonOps
swModel.ShowNamedView2 "*Top", -1 Call TransitionView_CommonOps
swModel.ShowNamedView2 "*Right", -1 Call TransitionView_CommonOps
swModel.ShowNamedView2 "*Bottom", -1 Call TransitionView_CommonOps
swModel.ShowNamedView2 "*Left", -1 Call TransitionView_CommonOps
swModel.ShowNamedView2 "*Back", -1 Call TransitionView_CommonOps
End If
'Rebuild File 'swModel.EditRebuild3 'Stoplight or [Ctrl]+B ' swModel.ForceRebuild '[Ctrl]+Q
Set swModel = Nothing Set swApp = Nothing
End Sub
Sub main()
Dim sIsoV As String Dim sFrontV As String Dim sBackV As String Dim sLeftV As String Dim sRightV As String Dim sTopV As String Dim sBottomV As String
Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc
If (swModel Is Nothing) Then MsgBox "No SolidWorks document open." & Chr(13) & "Routine ending.", vbCritical, "ModelView Rotation" End End If
If (swModel.GetType swDocDRAWING) Then
'Default SW - Key-string for model views sFrontV = "^1" ' 1 sBackV = "^2" ' 2 sLeftV = "^3" ' 3 sRightV = "^4" ' 4 sTopV = "^5" ' 5 sBottomV = "^6" ' 6 sIsoV = "^7" ' 7
SendKeys sIsoV Call TransitionView_CommonOps
SendKeys sFrontV Call TransitionView_CommonOps
SendKeys sRightV Call TransitionView_CommonOps
SendKeys sBackV Call TransitionView_CommonOps
SendKeys sLeftV Call TransitionView_CommonOps
SendKeys sFrontV Call TransitionView_CommonOps
SendKeys sTopV Call TransitionView_CommonOps
SendKeys sFrontV Call TransitionView_CommonOps
SendKeys sBottomV Call TransitionView_CommonOps
SendKeys sFrontV Call TransitionView_CommonOps
SendKeys sIsoV Call TransitionView_CommonOps
End If
MsgBox "Done!", vbOKOnly, "ModelView Rotation"
'Rebuild File 'swModel.EditRebuild3 'Stoplight or [Ctrl]+B ' swModel.ForceRebuild '[Ctrl]+Q
Set swModel = Nothing Set swApp = Nothing
End Sub