Hide Table of Contents

Select Entity in Drawing View Example (VB.NET)

This example shows how to select any of these entities in a drawing view: model face, edge, or vertex.

'----------------------------------------------------------------------------
' Problem:
'       Selection of a model geometry in the context of a drawing
'       view can be quite problematic. To address this, use
'       IView::SelectEntity
'
'       Thus, given an entity in the context of the model, this
'       method selects the entity in the context of the drawing
'       view.
'
'       This code shows how to use this method to assist in
'       adding a dimension to a drawing view.
'
' Preconditions:
' 1. Part or assembly is open.
' 2. Assembly is fully resolved.
' 3. Specified template exists.
' 4. Face, edge or vertex is selected.
'
' Postconditions:
' 1. New drawing is created with three views.
' 2. If possible, the previously selected face, edge or vertex
'    is dimensioned in the first drawing view.
'
' NOTE:  The dimension is not guaranteed to be created if, for
'        example, 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:\Program Files\SolidWorks\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)

        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

        
' This depends on the orientation of the entity in the drawing view.
        ' Thus, could be NULL.
        '
        ' Will also create the dimension even if the entity is not
        ' visible in the drawing view
        swDispDim = swDrawModel.AddDimension2(nXpos, nYpos, 0.0#)

    
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) 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.