Hide Table of Contents

Create and Name Planes Example (VBA)

This example shows how to create five planes that are offset from each other and change each of their names.

'---------------------------------------------------------
' Preconditions: Open a part that has three planes and
' one of the planes is named Plane1.
'
' Postconditions:
' 1. Creates five offset planes: MyPlane1, MyPlane2,
'    MyPlane3, MyPlane4, and MyPlane5.
' 2. Examine the FeatureManager design tree and graphics
'    area.
'--------------------------------------------------------
Option Explicit
Public Sub CreateOffsetPlanes()
    Dim swApp As SldWorks.SldWorks
    Dim Part As SldWorks.PartDoc
    Dim Model As SldWorks.ModelDoc2
    Dim planeName As String
    Dim newPlaneName As String
    Dim planeFeature As SldWorks.Feature
    Dim i As Long
    Dim planeCount As Long    
    Set swApp = CreateObject("SldWorks.Application")    
    ' Get the active document
    Set Model = swApp.ActiveDoc
    If Model Is Nothing Then
        Exit Sub
    End If    
    ' Set name of plane for SelectByID for
    ' first pass through the loop
    newPlaneName = "Plane1"    
    ' Currently three planes in the part
    planeCount = 3    
    ' If your model has more than three planes or you are not
    ' sure how many planes exist in your part, then immediately
    ' after loading the part you can traverse the FeatureManager design
    ' tree (see IPartDoc::FirstFeature) and count the reference plane
    ' features using IFeature::GetTypeName to determine which
    ' features are reference planes and add them up    
    ' Loop five times and create five planes offset from each other
    For i = 1 To 5
        Model.ClearSelection
        ' Select the plane from which to offset
        Model.SelectByID newPlaneName, "PLANE", 0, 0, 0
        ' Create plane offset from selected plane
        Model.CreatePlaneAtOffset 0.1, 0
        ' Increment the plane number
        planeCount = planeCount + 1
        ' Increment the plane name
        planeName = "Plane" & planeCount
        newPlaneName = "MyPlane" & i
        ' Get the Plane feature by its name
        Set planeFeature = Model.FeatureByName(planeName)
        ' Change the Plane name
        planeFeature.Name = (newPlaneName)        
        Model.EditRebuild
   Next
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:   Create and Name Planes 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.