Hide Table of Contents

Select Entity in Drawing View Example (VB.NET)

This example shows how to select a model face, edge, or vertex in a drawing view and dimension it.

'----------------------------------------------------------------------------
' Preconditions:
' 1. Open a part or fully resolved assembly.
' 2. Verify that the specified template exists.
' 3. Select a face, edge, or vertex.
'
' Postconditions:
' 1. Creates a new drawing with three views.
' 2. Dimensions the selected face, edge, or vertex
'    in the first drawing view.
' 3. Examine the drawing.
'
' NOTE: The dimension is not guaranteed to be created if a face is selected.
'----------------------------------------------------------------------------

Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
 
Partial Class SolidWorksMacro
 
    Sub main()
 
        Const sPathToTemplate As String = "C:\ProgramData\SolidWorks\SOLIDWORKS 2016\data\templates\drawing.drwdot"
        Const nYoffset As Double = 0.01
 
        Dim swModel As ModelDoc2
        Dim swSelMgr As SelectionMgr
        Dim swEnt As Entity
 
        Dim swDraw As DrawingDoc
        Dim swDrawModel As ModelDoc2
        Dim swView As View
        Dim vOutline As Object
        Dim swDispDim As DisplayDimension
 
        Dim nXpos As Double
        Dim nYpos As Double
 
        Dim bRet As Boolean
 
        swModel = swApp.ActiveDoc
        swSelMgr = swModel.SelectionManager
        swEnt = swSelMgr.GetSelectedObject6(1, -1)
 
        If Not swEnt Is Nothing Then
 
            swDraw = swApp.NewDrawing2(swDwgTemplates_e.swDwgTemplateCustom, sPathToTemplate, swDwgPaperSizes_e.swDwgPaperA1size, 0.0#, 0.0#)
            swDrawModel = swDraw
 
            bRet = swDraw.Create3rdAngleViews2(swModel.GetPathName)
 
            swView = swDraw.GetFirstView
            swView = swView.GetNextView
 
            bRet = swView.SelectEntity(swEnt, False)
 
            ' Work out where to place dimension -
            ' midway across view and slightly above
            vOutline = swView.GetOutline
            nXpos = (vOutline(0) + vOutline(2)) / 2.0#
            nYpos = vOutline(3) + nYoffset
 
            ' Create the dimension, even if the entity is not
            ' visible in the drawing view
            swDispDim = swDrawModel.Extension.AddDimension(nXpos, nYpos, 0.0#, swSmartDimensionDirection_e.swSmartDimensionDirection_Left)
 
        End If
 
    End Sub
 
    Public swApp As SldWorks
 
End Class

 

 



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:   Select Entity in Drawing View Example (VB.NET)
*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) 2024 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.