Hide Table of Contents

Create and Name Planes Example (VBA)

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

 

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

Public Sub CreateOffsetPlanes()

 

' Define variable used to hold the application object

Dim swApp As Object   

' Define variable used to hold the part object

Dim Part, Model As Object   

Dim planeName, newPlaneName As String

Dim planeFeature As Object

' This will attach to current SOLIDWORKS session or start up new session in background

Dim i, planeCount As Integer

Set swApp = CreateObject("SldWorks.Application")

 

' Grab the currently active document

Set Model = swApp.ActiveDoc  

If Model Is Nothing Then

Exit Sub

End If

 

' Set for SelectByID during the first pass through the loop

newPlaneName = "Plane1"  

' Currently 3 planes in the model

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 PartDoc::FirstFeature) and count the refernce plane features using Feature::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:   Plane Creation and Naming 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) 2016 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.