Hide Table of Contents

Select Entity in Drawing View Example (VBA)

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

'

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

Option Explicit

 

Public Enum swDwgTemplates_e

    swDwgTemplateAsize = 0

    swDwgTemplateAsizeVertical = 1

    swDwgTemplateBsize = 2

    swDwgTemplateCsize = 3

    swDwgTemplateDsize = 4

    swDwgTemplateEsize = 5

    swDwgTemplateA4size = 6

    swDwgTemplateA4sizeVertical = 7

    swDwgTemplateA3size = 8

    swDwgTemplateA2size = 9

    swDwgTemplateA1size = 10

    swDwgTemplateA0size = 11

    swDwgTemplateCustom = 12

    swDwgTemplateNone = 13

End Enum

Public Enum swDwgPaperSizes_e

    swDwgPaperAsize = 0

    swDwgPaperAsizeVertical = 1

    swDwgPaperBsize = 2

    swDwgPaperCsize = 3

    swDwgPaperDsize = 4

    swDwgPaperEsize = 5

    swDwgPaperA4size = 6

    swDwgPaperA4sizeVertical = 7

    swDwgPaperA3size = 8

    swDwgPaperA2size = 9

    swDwgPaperA1size = 10

    swDwgPaperA0size = 11

    swDwgPapersUserDefined = 12

End Enum

 

Sub main()

 

    Const sPathToTemplate       As String = "C:\Program Files\SolidWorks\data\templates\drawing.drwdot"

    

    Const nYoffset              As Double = 0.01

    

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swSelMgr                As SldWorks.SelectionMgr

    Dim swEnt                   As SldWorks.entity

    

    Dim swDraw                  As SldWorks.DrawingDoc

    Dim swDrawModel             As SldWorks.ModelDoc2

    Dim swView                  As SldWorks.view

    Dim vOutline                 As Variant

    Dim swDispDim               As SldWorks.DisplayDimension

    

    Dim nXpos                   As Double

    Dim nYpos                   As Double

    

    Dim bRet                    As Boolean

    

    Set swApp = CreateObject("SldWorks.Application")

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager

    Set swEnt = swSelMgr.GetSelectedObject5(1)

    

    Set swDraw = swApp.NewDrawing2(swDwgTemplateCustom, sPathToTemplate, swDwgPaperA1size, 0#, 0#)

    Set swDrawModel = swDraw

    

    bRet = swDraw.Create3rdAngleViews2(swModel.GetPathName)

    Debug.Assert bRet

    

    Set swView = swDraw.GetFirstView

    Set swView = swView.GetNextView

    

    bRet = swView.SelectEntity(swEnt, False)

    Debug.Assert bRet

    

    ' Work out where to place dimension -

    ' midway across view and slightly above

    vOutline = swView.GetOutline

    nXpos = (vOutline(0) + vOutline(2)) / 2#

    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

    Set swDispDim = swDrawModel.AddDimension2(nXpos, nYpos, 0#)

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:   Select Entity in Drawing View 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) 2012 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.