Hide Table of Contents

Convert Drawing Views to Sketch Blocks Example (VBA)

This example shows how to convert drawing views to sketches and sketch blocks.

' Preconditions: Open:
'    install_dir\samples\tutorial\api\ReplaceView.slddrw
' Postconditions:
' 1. Drawing View1 is converted to a sketch.
' 2. Drawing View2 is converted to a sketch block
' 3. Drawing View3 is converted to a sketch block at a new position in the drawing.
' NOTE: Because the model is used elsewhere,
' do not save changes when closing it.
' ---------------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim drawDoc As SldWorks.DrawingDoc
Dim selMan As SldWorks.SelectionMgr
Dim drview As SldWorks.View
Dim nPt(2) As Double
Dim vPt    As Variant
Dim swMathUtil               As SldWorks.MathUtility
Dim insertionPt              As SldWorks.MathPoint
Dim position                 As SldWorks.MathPoint
Option Explicit
Sub main()
    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc
    Set drawDoc = Part
    Set swMathUtil = swApp.GetMathUtility
    Set selMan = Part.SelectionManager
    boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
    Set drview = selMan.GetSelectedObject6(1, 0)
    boolstatus = drview.ReplaceViewWithSketch
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID2("Drawing View2", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
    Set drview = selMan.GetSelectedObject6(1, 0)
    nPt(0) = 1.41
    nPt(1) = 3.88
    nPt(2) = 0
    vPt = nPt
    Set insertionPt = swMathUtil.CreatePoint(vPt)
    boolstatus = drview.ReplaceViewWithBlock(insertionPt)
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID2("Drawing View3", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
    Set drview = selMan.GetSelectedObject6(1, 0)
    nPt(0) = 5.48
    nPt(1) = 5.22
    nPt(2) = 0
    vPt = nPt
    Set position = swMathUtil.CreatePoint(vPt)
    boolstatus = drview.InsertViewAsBlock(insertionPt, position)
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:   Convert Drawing Views to Sketch Blocks 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) 2013 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.