Hide Table of Contents

Drop Drawing Views from View Palette Example (VBA)

This example shows how to drop drawing views from the View Palette.

 

'------------------------------------

'

' Preconditions: Part or assembly document is

'                open. Drawing document is open and

'                active, and the part or assembly

'                document is selected in View Palette.

'

' Postconditions: Current, Isometric, and Front views

'                are dropped on to the drawing sheet.

'

'-------------------------------------

Option Explicit

 

Dim swApp As SldWorks.SldWorks

 

Sub main()

    Dim swModel            As SldWorks.ModelDoc2

    Dim swDrawing          As SldWorks.DrawingDoc

    Dim swFeature          As SldWorks.Feature

    Dim swSubFeature       As SldWorks.Feature

    Dim swSheet            As SldWorks.Sheet

    Dim swView             As SldWorks.View

    Dim bFound             As Boolean

    Dim vViewNames         As Variant

    Dim vViewName          As Variant

    Dim strViewName        As String

    Dim lNumViews          As Long

    Dim dSheetScale        As Double

    Dim vSheetProperties   As Variant

    Dim nPaperSize         As swDwgPaperSizes_e

    Dim dWidth             As Double

    Dim dHeight            As Double

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swDrawing = swModel

    

    ' Get current sheet.

    Set swSheet = swDrawing.GetCurrentSheet

    vSheetProperties = swSheet.GetProperties

    dSheetScale = vSheetProperties(2) / vSheetProperties(3)

    nPaperSize = swSheet.GetSize(dWidth, dHeight)

    

    Debug.Print "Sheet scale  = " & dSheetScale

    Debug.Print "Sheet width  = " & dWidth

    Debug.Print "Sheet height = " & dHeight

    

    lNumViews = 0

    vViewNames = swDrawing.GetDrawingPaletteViewNames

        

    If (Not (IsEmpty(vViewNames))) Then

        lNumViews = (UBound(vViewNames) - LBound(vViewNames) + 1)

        Debug.Print "Number of views on palette = " & lNumViews

        For Each vViewName In vViewNames

            strViewName = vViewName

            Debug.Print strViewName

            If (strViewName = "*Current") Then

                Set swView = swDrawing.DropDrawingViewFromPalette2(strViewName, 0#, 0#, 0#)

                Debug.Print "  Dropped => " & swView.Name

            End If

            If (strViewName = "*Isometric") Then

                Set swView = swDrawing.DropDrawingViewFromPalette2(strViewName, dWidth / 2#, dHeight / 2#, 0#)

                Debug.Print "  Dropped => " & swView.Name

            End If

            If (strViewName = "*Front") Then

                Set swView = swDrawing.DropDrawingViewFromPalette2(strViewName, dWidth / 1#, dHeight / 1#, 0#)

                Debug.Print "  Dropped => " & swView.Name

            End If

        Next vViewName

    End If

End Sub



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Drop Drawing Views from View Palette Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.