Hide Table of Contents

SOLIDWORKS API Help

Creating Bounding Box Example (VBA)

This example shows how to create a bounding box.

'----------------------------------------------------------------------------
' Preconditions: Ensure that the specified model exists.
'
' Postconditions:
' 1. Creates Bounding Box in the FeatureManager design tree.
' 2. Modifies Bounding Box.
'
' NOTE: Because the model is used elsewhere, do not save changes.
'----------------------------------------------------------------------------

Dim swApp As SldWorks.SldWorks
Dim swGPData As SldWorks.BoundingBoxFeatureData
Dim featdata As SldWorks.BoundingBoxFeatureData
Dim Part As SldWorks.ModelDoc2
Dim ent As SldWorks.Face2
Dim feat As SldWorks.Feature
Dim featmgr As SldWorks.FeatureManager
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Option Explicit
Sub main()

    Set swApp = Application.SldWorks
   

    Set Part = swApp.OpenDoc6("C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2019\samples\tutorial\api\block20.sldprt", 1, 0, "", longstatus, longwarnings)
    swApp.ActivateDoc2 "block20.sldprt", False, longstatus
    Set Part = swApp.ActiveDoc
  

    Set featmgr = Part.FeatureManager
   

    boolstatus = Part.Extension.SelectByRay(1.08472195143463E-02, 3.96239999998329E-02, -1.01823136031953E-03, -0.400036026779312, -0.515038074910024, -0.758094294050284, 1.1224765174324E-03, 2, False, 0, 0)
  

    Set ent = Part.SelectionManager.GetSelectedObject6(1, -1)
    Set swGPData = featmgr.CreateDefinition(swFmBoundingBox)
    swGPData.ReferenceFaceOrPlane = 2
    swGPData.PlanarEntity = ent
   

    Set feat = featmgr.CreateFeature(swGPData)
    Part.ClearSelection2 True
   

    Set featdata = feat.GetDefinition()
    featdata.AccessSelections Part, Nothing
    boolstatus = Part.Extension.SelectByRay(-1.03569711794194E-02, 1.88454182651299E-02, 0.049345602378537, -0.400036026779312, -0.515038074910024, -0.758094294050284, 1.1224765174324E-03, 2, False, 0, 0)
    Set ent = Part.SelectionManager.GetSelectedObject6(1, -1)
    featdata.PlanarEntity = ent
    featdata.IncludeSurfaces = True
    featdata.IncludeHiddenBodies = True
    feat.ModifyDefinition featdata, Part, Nothing
   

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:   Creating Bounding Box 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) 2019 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.