Recalculate Bounding Box Example (VBA)
This example shows how to recalculate the bounding box of an assembly.
'-----------------------------------------------
'
' Preconditions: Assembly document is open.
'
' Postconditions: Bounding box is updated.
'
'------------------------------------------------
Option Explicit
Public Enum swBoundingBoxOptions_e
swBoundingBoxIncludeRefPlanes
= &H1
swBoundingBoxIncludeSketches
= &H2
End Enum
Sub ProcessAssyBox _
( _
swApp
As SldWorks.SldWorks, _
swAssy
As SldWorks.AssemblyDoc _
)
Dim
vBox As Variant
vBox
= swAssy.GetBox(0)
Debug.Print
" Min
= (" & vBox(0) * 1000# & ", " & vBox(1) * 1000#
& ", " & vBox(2) * 1000# & ") mm"
Debug.Print
" Max
= (" & vBox(3) * 1000# & ", " & vBox(4) * 1000#
& ", " & vBox(5) * 1000# & ") mm"
End Sub
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swAssy As
SldWorks.AssemblyDoc
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swAssy = swModel
Debug.Print
"Before:"
ProcessAssyBox
swApp, swAssy
'
Do something that changes the bounding box
swAssy.UpdateBox
Debug.Print
"After:"
ProcessAssyBox
swApp, swAssy
End Sub
'-----------------------------------------------