US$0.00
0

SOLIDWORKS Macro to Create Custom ISO Views (8 Orientations)

Description

  • Creates eight custom-named ISO views (based on front, right, back, and left, viewed from top and bottom).
  • Enables quicker, consistent access to ISO views beyond the standard two.
SOLIDWORKS Macro to Create Custom ISO Views and n image divided into two side-by-side sections labeled "Before" and "After," showing a SOLIDWORKS software interface. The "Before" section displays a partially constructed 3D model of a valve with a few extruded components and a feature tree on the left listing steps like "Base Extrude" and "Cut Extrude." The workspace is mostly empty with a gray background. The "After" section shows the completed 3D model of the valve, featuring a more detailed structure with multiple cylindrical and connected parts, and the same feature tree on the left with additional steps like "Fillet" and "Mirror." Both sections include toolbars and menus at the top, with the "After" section highlighting the finalized design in a 3D view.

System Requirements

  • SOLIDWORKS Version: SOLIDWORKS 2014 or newer
  • Operating System: Windows 7 or later

Pre-requisites

  • An open document of SOLIDWORKS must be active.
  • It is best to use a 3D model, as the ISO views generated will represent geometric perspectives with meaning and use.

Results

  • Eight ISO views are generated, and the name is customized for easy identification and use.
  • The macro will then delete any previously named views that have the same eight names before creating them, giving us a set of custom ISO views that will not cause duplicates.

Steps to Implement the Macro

  1. Open the File: You should have a 3D model file open in SOLIDWORKS where ISO views can be meaningfully generated.
  2. Load and Run the Macro:
  3. Using the Macro:

VBA Macro Code

' Disclaimer:
' The code provided should be used at your own risk.  
' Blue Byte Systems Inc. assumes no responsibility for any issues or damages that may arise from using or modifying this code.  
' For more information, visit [Blue Byte Systems Inc.](https://bluebyte.biz).

' *********************************************************
' Description:
' This macro creates a series of isometric views and saves them as named views in the active SolidWorks document.
' *********************************************************

Sub main()
    ' Declare SolidWorks application and document variables
    Dim swApp As Object                            ' SolidWorks application object
    Dim Part As Object                             ' Active document object
    Dim boolstatus As Boolean                      ' Boolean to capture status (not used in this macro)
    Dim longstatus As Long                         ' Long status for operations (not used in this macro)
    Dim Annotation As Object                       ' Annotation object placeholder (not used here)
    Dim Gtol As Object                             ' Geometric tolerance object placeholder (not used here)
    Dim DatumTag As Object                         ' Datum tag object placeholder (not used here)
    Dim FeatureData As Object                      ' Feature data placeholder (not used here)
    Dim Feature As Object                          ' Feature object placeholder (not used here)
    Dim Component As Object                        ' Component object placeholder (not used here)

    ' Initialize SolidWorks application and active document
    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc

    ' Check if a document is open
    If Part Is Nothing Then
        MsgBox "No active document found. Please open a model.", vbExclamation, "Error"
        Exit Sub
    End If

    ' Define mathematical constants and view transformations
    pi = 4 * Atn(1)                               ' Value of π (pi)
    Z = Tan(30 * pi / 180)                        ' Tangent of 30 degrees
    X = Atn(Z / Sqr(-Z * Z + 1))                  ' Rotation angle in radians for X-axis
    Y = -45 * pi / 180                            ' Rotation angle in radians for Y-axis

    ' Delete previously saved ISO views to ensure clean state
    Part.DeleteNamedView ("TRF-ISO")
    Part.DeleteNamedView ("TRR-ISO")
    Part.DeleteNamedView ("TLF-ISO")
    Part.DeleteNamedView ("TLR-ISO")
    Part.DeleteNamedView ("BRF-ISO")
    Part.DeleteNamedView ("BRR-ISO")
    Part.DeleteNamedView ("BLF-ISO")
    Part.DeleteNamedView ("BLR-ISO")

    ' Create and save named views for different ISO perspectives
    ' Top Right Front ISO View
    Part.ShowNamedView2 "*Front", -1
    Part.ActiveView().RotateAboutCenter X, Y
    Part.ViewZoomtofit
    Part.NameView ("TRF-ISO")

    ' Top Right Rear ISO View
    Part.ShowNamedView2 "*Right", -1
    Part.ActiveView().RotateAboutCenter X, Y
    Part.ViewZoomtofit
    Part.NameView ("TRR-ISO")

    ' Top Left Rear ISO View
    Part.ShowNamedView2 "*Back", -1
    Part.ActiveView().RotateAboutCenter X, Y
    Part.ViewZoomtofit
    Part.NameView ("TLR-ISO")

    ' Top Left Front ISO View
    Part.ShowNamedView2 "*Left", -1
    Part.ActiveView().RotateAboutCenter X, Y
    Part.ViewZoomtofit
    Part.NameView ("TLF-ISO")

    ' Bottom Right Front ISO View
    Part.ShowNamedView2 "*Front", -1
    Part.ActiveView().RotateAboutCenter -X, Y
    Part.ViewZoomtofit
    Part.NameView ("BRF-ISO")

    ' Bottom Right Rear ISO View
    Part.ShowNamedView2 "*Right", -1
    Part.ActiveView().RotateAboutCenter -X, Y
    Part.ViewZoomtofit
    Part.NameView ("BRR-ISO")

    ' Bottom Left Rear ISO View
    Part.ShowNamedView2 "*Back", -1
    Part.ActiveView().RotateAboutCenter -X, Y
    Part.ViewZoomtofit
    Part.NameView ("BLR-ISO")

    ' Bottom Left Front ISO View
    Part.ShowNamedView2 "*Left", -1
    Part.ActiveView().RotateAboutCenter -X, Y
    Part.ViewZoomtofit
    Part.NameView ("BLF-ISO")

    ' Clean up objects
    Set Part = Nothing
    Set swApp = Nothing
End Sub

Macro

You can download the macro from here

Need to modify the macro to meet specific requirements?

Contact us today to see how our experience can help provide you with a custom solution for maximizing your engineering efficiency.

Author

Amen Jlili

Amen Jlili is the founder and technical director of Blue Byte Systems Inc., a software company in Vancouver, Canada, specializing in automating SOLIDWORKS and PDM. With over a decade of experience, he has authored several courses and open-source frameworks related to the SOLIDWORKS API. His leadership ensures that Blue Byte Systems prioritizes customer satisfaction and delivers high-quality software and CAD design solutions.
0
    0
    Your Cart
    Your cart is emptyReturn to Shop
    ×