Hide Table of Contents

Get Assembly Bounding Box using Assembly Example (VBA)

This example shows how to get the box bounding an assembly using the assembly.

 

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

'

' Preconditions: Assembly document is open.

'

' Postconditions: 3D sketch representing a bounding box

'               enclosing assembly is created.

'

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

 

Option Explicit

Public Enum swBoundingBoxOptions_e

    swBoundingBoxIncludeRefPlanes = &H1

    swBoundingBoxIncludeSketches = &H2

End Enum

Sub main()

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swAssy                  As SldWorks.AssemblyDoc

    Dim vBox                    As Variant

    Dim X_max                   As Double

    Dim X_min                   As Double

    Dim Y_max                   As Double

    Dim Y_min                   As Double

    Dim Z_max                   As Double

    Dim Z_min                   As Double

    

    Dim swSketchPt(8)           As SldWorks.SketchPoint

    Dim swSketchSeg(12)         As SldWorks.SketchSegment

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swAssy = swModel

    

    vBox = swAssy.GetBox(0)

    X_max = vBox(3)

    X_min = vBox(0)

    Y_max = vBox(4)

    Y_min = vBox(1)

    Z_max = vBox(5)

    Z_min = vBox(2)

    swModel.Insert3DSketch2 True

    swModel.SetAddToDB True

    

    ' Draw points at each corner of bounding box

    Set swSketchPt(0) = swModel.CreatePoint2(X_min, Y_min, Z_min)

    Set swSketchPt(1) = swModel.CreatePoint2(X_min, Y_min, Z_max)

    Set swSketchPt(2) = swModel.CreatePoint2(X_min, Y_max, Z_min)

    Set swSketchPt(3) = swModel.CreatePoint2(X_min, Y_max, Z_max)

    Set swSketchPt(4) = swModel.CreatePoint2(X_max, Y_min, Z_min)

    Set swSketchPt(5) = swModel.CreatePoint2(X_max, Y_min, Z_max)

    Set swSketchPt(6) = swModel.CreatePoint2(X_max, Y_max, Z_min)

    Set swSketchPt(7) = swModel.CreatePoint2(X_max, Y_max, Z_max)

    

    ' Draw bounding box

    Set swSketchSeg(0) = swModel.CreateLine2(X_min, Y_min, Z_min, X_max, Y_min, Z_min)

    Set swSketchSeg(1) = swModel.CreateLine2(X_max, Y_min, Z_min, X_max, Y_min, Z_max)

    Set swSketchSeg(2) = swModel.CreateLine2(X_max, Y_min, Z_max, X_min, Y_min, Z_max)

    Set swSketchSeg(3) = swModel.CreateLine2(X_min, Y_min, Z_max, X_min, Y_min, Z_min)

    

    Set swSketchSeg(4) = swModel.CreateLine2(X_min, Y_min, Z_min, X_min, Y_max, Z_min)

    Set swSketchSeg(5) = swModel.CreateLine2(X_min, Y_min, Z_max, X_min, Y_max, Z_max)

    Set swSketchSeg(6) = swModel.CreateLine2(X_max, Y_min, Z_min, X_max, Y_max, Z_min)

    Set swSketchSeg(7) = swModel.CreateLine2(X_max, Y_min, Z_max, X_max, Y_max, Z_max)

    

    Set swSketchSeg(8) = swModel.CreateLine2(X_min, Y_max, Z_min, X_max, Y_max, Z_min)

    Set swSketchSeg(9) = swModel.CreateLine2(X_max, Y_max, Z_min, X_max, Y_max, Z_max)

    Set swSketchSeg(10) = swModel.CreateLine2(X_max, Y_max, Z_max, X_min, Y_max, Z_max)

    Set swSketchSeg(11) = swModel.CreateLine2(X_min, Y_max, Z_max, X_min, Y_max, Z_min)

    

    swModel.SetAddToDB False

    swModel.Insert3DSketch2 True

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 Assembly Bounding Box using Assembly 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) 2012 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.