Hide Table of Contents

Create Plane thru 3 Points In-context Example (VBA)

This example shows how to create a plane through 3 points in-context.

' Preconditions:
' 1. Open a fully resolved assembly.
' 2. Select a component.
' 3. Expand the selected component in the FeatureManager
'    design tree.
' Postconditions:
' 1. Creates a plane, passing through three points,
'    in the selected component.
' 2. Examine the selected component in the FeatureManager
'    design tree to verify that a 3D sketch and plane
'    were created.
Option Explicit
'  Possible status values for AssemblyDoc::EditPart2
Public Enum swEditPartCommandStatus_e
    swEditPartFailure = -1
    swEditPartAsmMustBeSaved = -2
    swEditPartCompMustBeSelected = -3
    swEditPartCompMustBeResolved = -4
    swEditPartCompMustHaveWriteAccess = -5
    swEditPartSuccessful = 0
    swEditPartCompNotPositioned = &H1
End Enum
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swAssy As SldWorks.AssemblyDoc
    Dim swEditModel As SldWorks.ModelDoc2
    Dim swSelMgr As SldWorks.SelectionMgr
    Dim swSelData As SldWorks.SelectData
    Dim swPart As SldWorks.PartDoc
    Dim swSketchPt1 As SldWorks.SketchPoint
    Dim swSketchPt2 As SldWorks.SketchPoint
    Dim swSketchPt3 As SldWorks.SketchPoint
    Dim swPlane As SldWorks.RefPlane
    Dim nRetVal As Long
    Dim nInfo As Long
    Dim bRet As Boolean
    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    Set swSelData = swSelMgr.CreateSelectData
    Set swAssy = swModel
    ' Start in-context edit
    nRetVal = swAssy.EditPart2(True, False, nInfo)
    Debug.Assert swEditPartSuccessful = nRetVal
    Set swEditModel = swModel
    ' Turn off snapping
    swEditModel.SetAddToDB True
    ' Insert part/component 3D sketch in-context
    swEditModel.Insert3DSketch2 True
    ' Create points in part
    Set swSketchPt1 = swEditModel.CreatePoint2(0#, 0.02123307340457, 0.005485856156458)
    Set swSketchPt2 = swEditModel.CreatePoint2(0.04415646169588, 0.01166034702997, -0.00770979679615)
    Set swSketchPt3 = swEditModel.CreatePoint2(0#, -0.006247647329005, 0.007641244473859)
    ' Exit sketch but in assembly
    ' This gets you to editing part/component in-context
    swModel.Insert3DSketch2 True
    ' Restore snapping
    swEditModel.SetAddToDB False
    swModel.ClearSelection2 True

    bRet = swSketchPt1.Select4(True, swSelData): Debug.Assert bRet
    bRet = swSketchPt2.Select4(True, swSelData): Debug.Assert bRet
    bRet = swSketchPt3.Select4(True, swSelData): Debug.Assert bRet
    ' Create plane in part/component
    Set swPlane = swModel.CreatePlaneThru3Points3(True)
    Debug.Assert Not swPlane Is Nothing
    ' Go back to assembly
    ' End in-context edit
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

Subject:   Feedback on Help Topics
Page:   Create Plane thru 3 Points In-context Example (VBA)
*   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:


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

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.