Hide Table of Contents

Get Plane or Face for Sketch Example (VBA)

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

'-----------------------------------------------------
' Preconditions:
' 1. Open apart or assembly.
' 2. Select a sketch.
' 3. Open the Immediate window.
'
' Postconditions:
' 1. Selects the plane or face on which the selected 
'    sketch was drawn.
' 2. Examine the Immediate window and graphics area.
'----------------------------------------------------
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:  
*   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) 2017 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.