Hide Table of Contents

Get Plane or Face for Sketch Example (VBA)

This example shows how to get the plane of the face on which a selected sketch was drawn.

 

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

'

' Preconditions:

'       (1) Part or assembly is open.

'       (2) Sketch is selected.

'

' Postconditions: Plane or face on which selected sketch was drawn is selected.

'

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

Option Explicit

Sub main()

    Dim pSWApp                      As SldWorks.SldWorks

    Dim pModel                      As SldWorks.ModelDoc2

    Dim pSelMgr                     As SldWorks.SelectionMgr

    Dim pFeat                       As SldWorks.Feature

    Dim pSketch                     As SldWorks.sketch

    Dim pEntity                     As SldWorks.entity

    Dim pPlaneFeat                  As SldWorks.Feature

    Dim pFace                       As SldWorks.face2

    Dim pRefPlane                   As SldWorks.refPlane

    Dim vPlaneParams                As Variant

    Dim vNormal                     As Variant

    Dim bRet                        As Boolean

    Dim nEntType                    As Long

    

    Set pSWApp = CreateObject("SldWorks.Application")

    Set pModel = pSWApp.ActiveDoc

    Set pSelMgr = pModel.SelectionManager

    Set pFeat = pSelMgr.GetSelectedObject5(1)

    Set pSketch = pFeat.GetSpecificFeature2

    Set pEntity = pSketch.GetReferenceEntity(nEntType)

    

    Debug.Print "Sketch Name = " + pFeat.Name

    

    If nEntType = swSelDATUMPLANES Then

        Set pPlaneFeat = pEntity

        Set pRefPlane = pEntity

        

        vPlaneParams = pRefPlane.GetRefPlaneParams

        

        Debug.Print "Plane Selected!"

        Debug.Print "  Origin   = (" + _

                            Str(vPlaneParams(0) * 1000#) + "," + _

                            Str(vPlaneParams(1) * 1000#) + "," + _

                            Str(vPlaneParams(2) * 1000#) + ") mm"

        Debug.Print "  Xvector  = (" + _

                            Str(vPlaneParams(3)) + "," + _

                            Str(vPlaneParams(4)) + "," + _

                            Str(vPlaneParams(5)) + ")"

        Debug.Print "  Normal   = (" + _

                            Str(vPlaneParams(6)) + "," + _

                            Str(vPlaneParams(7)) + "," + _

                            Str(vPlaneParams(8)) + ")"

        

        ' Cannot select through Entity; must

        ' select through Feature

        bRet = pPlaneFeat.Select2(False, 0)

    End If

    

    If nEntType = swSelFACES Then

        Set pFace = pEntity

        

        vNormal = pFace.Normal

        

        Debug.Print "Face Selected!"

        Debug.Print "  Normal   = (" + _

                            Str(vNormal(0)) + "," + _

                            Str(vNormal(1)) + "," + _

                            Str(vNormal(2)) + ")"

        

        bRet = pEntity.Select2(False, 0)

    End If

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:   Get Plane or Face for Sketch Example (VBA)
*Comment:  

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) 2014 SP05

The search functionality within the web help is in a beta test phase and you may experience periodic delays or interruptions in its performance. These are the normal and ordinary features of a beta test and shall not under any circumstances give rise to any liability on the part of Dassault Systèmes SolidWorks Corporation or its licensors. The topics within the Web-based help are not beta topics; they document API Help (English only) 2014 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.