Hide Table of Contents

Create Section View at Specified Location Example (VBA)

This example shows how to create a section view at a specified location.




' Preconditions: Drawing document with at least one view is open.


' Postconditions: Section view created at specified location.




Dim swApp As SldWorks.SldWorks

Dim swDrawing As SldWorks.DrawingDoc

Dim vChildComponents As Variant

Dim swFirstDrawingView As SldWorks.View

Dim swDrawingView As SldWorks.View

Dim swDrRootComponent As SldWorks.DrawingComponent

Sub main()

    Set swApp = Application.SldWorks

    Set swDrawing = swApp.ActiveDoc

    If swDrawing Is Nothing Then

        MsgBox "There is no active document"

        Exit Sub

    End If


    ' Always return the drawing sheet

    Set swFirstDrawingView = swDrawing.GetFirstView


    ' Get next drawing sheet

    Set swDrawingView = swFirstDrawingView.GetNextView


    ' Get  root drawing component

    Set swDrRootComponent = swDrawingView.RootDrawingComponent


    If swDrRootComponent.GetChildrenCount > 0 Then

        vChildComponents = swDrRootComponent.GetChildren

        For iChild = 0 To UBound(vChildComponents)

        Next iChild

    End If


    ' Select the drawing view and create line for the section view

    boolstatus = swDrawing.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.1776750819672, 0.1542113114754, 0, False, 0, Nothing, swSelectOptionDefault)

    swDrawing.ClearSelection2 True

    swDrawing.CreateLine2 -0.1627297255825, 0.003478881358533, 0, 0.1883732252372, 0.003478881358533, 0


    ' Set arguments for call to create section view

    Dim x As Double, y As Double, z As Double

    Dim notAligned As Boolean, isOffsetSection As Boolean, chgdirection As Boolean, scwithmodel As Boolean, partial As Boolean, dispsurfcut As Boolean

    Dim label As String

    Dim sectionView As SldWorks.View


    x = 0.2222307644306

    y = 0.08908737704918

    z = 0

    notAligned = False

    isOffsetSection = False

    chgdirection = False

    scwithmodel = False

    partial = False

    dispsurfcut = False

    label = "A"


    ' Create section view

    Set sectionView = swDrawing.CreateSectionViewAt3(x, y, z, notAligned, isOffsetSection, label, chgdirection, scwithmodel, partial, dispsurfcut, (vChildComponents))


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

Subject:   Feedback on Help Topics
Page:   Create Section View at Specified Location Example (VBA)
*   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:


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

Web Help Content Version: API Help (English only) 2016 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.