Code:
'Copyright 2008 by Milton R. Hartung, Kamco Industries, Inc. (MiltonRH@kamcoind.com)
'Released under a creative commons Attribution-ShareAlike 3.0 license (http://creativecommons.org/licenses/by-sa/3.0/)
'
'code modified from bib or solid7 from http://2htts.com/CATBlog/index.php?itemid=24'Creates a solid bounding box around a solid or surface, with the option to set offset on each face
'The document must be a CATPart
'Inputs:
' - an Axis System
' - A Face (Solid/Joined Surf will be chosen based on selection)
'----------------------------------------------------------------------------------------------------------------------------------
Sub CATMain()
'Make sure they have axis ready and want to start
CATIA.DisplayFileAlerts = False
Dim Message, Style, Title, Response, MyString
Message = ("This macro will create a solid bounding box around a solid or a joined surface, using an axis system. For useful results," & _
(Chr(13)) & _
"the axis should be based on some tooling directions, or created from the Measure Inertia command (for best fit), not XYZ." & _
(Chr(13)) & _
"You will be prompted to select an Axis System and a Face belonging to the object you wish to bound." & _
(Chr(13)) & _
(Chr(13)) & _
" - The active document must be a CATPart" & _
(Chr(13)) & _
" - The Axis System must be previously created" & _
(Chr(13)) & _
"" & (Chr(13)) & _
" Are you ready to continue?")
Style = vbYesNo 'Define buttons.
If MsgBox(Message, Style) = vbYes Then
'Declare variables
Dim axis
Dim remake
Dim partDocument1 As PartDocument
Dim part1 As Part
Dim axisref As Object
Dim shapeFactory1 As ShapeFactory
Dim hybridShapeFactory1 As HybridShapeFactory
Dim sStatus As String
Dim hybridShapeD1, hybridShapeD2, hybridShapeD3 As HybridShapeDirection
Dim Default, a1, a2, a3, a4, a5, a6 'To change the offsets of the box
Dim bodies1 As Bodies
Dim body1 As Body
Dim reference1 As Reference
Dim HybridShapeExtremum1, HybridShapeExtremum2, HybridShapeExtremum3 As HybridShapeExtremum
Dim HybridShapeExtremum4, HybridShapeExtremum5, HybridShapeExtremum6 As HybridShapeExtremum
Dim originCoord(2)
Dim selection As Object
Set partDocument1 = CATIA.ActiveDocument
If (InStr(partDocument1.Name, ".CATPart")) <> 0 Then
Set part1 = partDocument1.Part
Set selection = partDocument1.selection
part1.Update
Set hybridShapeFactory1 = part1.HybridShapeFactory
ReDim sFilter(0)
MsgBox "Select the axis to base the bounding on."
sFilter(0) = "AxisSystem"
sStatus = selection.SelectElement2(sFilter, "Select the axis to base the bounding on.", False)
Dim axiscoord(2)
Dim axissyst
Set axissyst = selection.Item(1).Value
Set axisref = selection.Item(1).Value
ref_name_systaxis = axissyst.Name
axissyst.IsCurrent = 1
axissyst.Name = "BBoxAxis"
axname = axissyst.Name
Dim originpoint As HybridShapePointCoord
axissyst.GetOrigin originCoord
Set originpoint = hybridShapeFactory1.AddNewPointCoord(originCoord(0), originCoord(1), originCoord(2))
Set axisref = part1.CreateReferenceFromObject(originpoint)
axissyst.GetXAxis axiscoord
Set hybridShapeD1 = hybridShapeFactory1.AddNewDirectionByCoord(axiscoord(0), axiscoord(1), axiscoord(2))
axissyst.GetYAxis axiscoord
Set hybridShapeD2 = hybridShapeFactory1.AddNewDirectionByCoord(axiscoord(0), axiscoord(1), axiscoord(2))
axissyst.GetZAxis axiscoord
Set hybridShapeD3 = hybridShapeFactory1.AddNewDirectionByCoord(axiscoord(0), axiscoord(1), axiscoord(2))
Dim Plane_line_1 As HybridShapeLinePtDir
Set Plane_line_1 = hybridShapeFactory1.AddNewLinePtDir(originpoint, hybridShapeD1, 0, 0, False)
Dim Plane_line_2 As HybridShapeLinePtDir
Set Plane_line_2 = hybridShapeFactory1.AddNewLinePtDir(originpoint, hybridShapeD2, 0, 0, False)
selection.Clear
Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Dim oBodies As Bodies
Set oBodies = part1.Bodies
'J is defined to make unique names for Axis and the Body for the bounding box
Dim j As Integer
j = oBodies.Count
Set bodies1 = part1.Bodies
Set body1 = bodies1.Add()
body1.Name = "Bounding Box." & j
Set hybridBodies1 = body1.HybridBodies
Set hybridBody1 = hybridBodies1.Add
hybridBody1.Name = "definition_points"
' Ask for face selection, that belongs to object to boundary
ReDim sFilter(0)
MsgBox "Select a face that belongs to the solid to be bounded."
sFilter(0) = "Face"
sStatus = selection.SelectElement2(sFilter, "Select a face that belongs to the solid to be bounded.", False)
If (sStatus = "Cancel") Then
Exit Sub
End If
Set reference1 = selection.Item(1).Value
Dim hybridShapeExtract1 As HybridShapeExtract
Set hybridShapeExtract1 = hybridShapeFactory1.AddNewExtract(reference1)
hybridShapeExtract1.PropagationType = 1
hybridShapeExtract1.ComplementaryExtract = False
hybridShapeExtract1.IsFederated = False
Set reference1 = hybridShapeExtract1
'Create the 6 Extrenum items for the Solid/Surf. May not be single points, will be solved with next points
Set HybridShapeExtremum1 = hybridShapeFactory1.AddNewExtremum(reference1, hybridShapeD1, 1)
Set HybridShapeExtremum2 = hybridShapeFactory1.AddNewExtremum(reference1, hybridShapeD1, 0)
Set HybridShapeExtremum3 = hybridShapeFactory1.AddNewExtremum(reference1, hybridShapeD2, 1)
Set HybridShapeExtremum4 = hybridShapeFactory1.AddNewExtremum(reference1, hybridShapeD2, 0)
Set HybridShapeExtremum5 = hybridShapeFactory1.AddNewExtremum(reference1, hybridShapeD3, 1)
Set HybridShapeExtremum6 = hybridShapeFactory1.AddNewExtremum(reference1, hybridShapeD3, 0)
part1.Update
' Creates Geometrical Set under the Solid, to contain the construction elements
Dim hybridBody2 As HybridBody
Set hybridBody2 = hybridBodies1.Item("definition_points")
hybridBody2.AppendHybridShape HybridShapeExtremum1
part1.InWorkObject = HybridShapeExtremum1
HybridShapeExtremum1.Name = "max_X"
hybridBody2.AppendHybridShape HybridShapeExtremum2
part1.InWorkObject = HybridShapeExtremum2
HybridShapeExtremum2.Name = "min_X"
hybridBody2.AppendHybridShape HybridShapeExtremum3
part1.InWorkObject = HybridShapeExtremum3
HybridShapeExtremum3.Name = "max_Y"
hybridBody2.AppendHybridShape HybridShapeExtremum4
part1.InWorkObject = HybridShapeExtremum4
HybridShapeExtremum4.Name = "min_Y"
hybridBody2.AppendHybridShape HybridShapeExtremum5
part1.InWorkObject = HybridShapeExtremum5
HybridShapeExtremum5.Name = "max_Z"
hybridBody2.AppendHybridShape HybridShapeExtremum6
part1.InWorkObject = HybridShapeExtremum6
HybridShapeExtremum6.Name = "min_Z"
part1.Update
' Creates a 6 single points using the Extrenums as refs, so if the Extrenum was a line or surf, you can still offset planes to these points
Dim Ref1 As Reference
Set Ref1 = part1.CreateReferenceFromObject(HybridShapeExtremum1)
Dim Point1 As HybridShapePointCoord
Set Point1 = hybridShapeFactory1.AddNewPointCoordWithReference(0, 0, 0, Ref1)
hybridBody2.AppendHybridShape Point1
Set point_ref11 = part1.CreateReferenceFromObject(Point1)
Dim Ref2 As Reference
Set Ref2 = part1.CreateReferenceFromObject(HybridShapeExtremum2)
Dim Point2 As HybridShapePointCoord
Set Point2 = hybridShapeFactory1.AddNewPointCoordWithReference(0, 0, 0, Ref2)
hybridBody2.AppendHybridShape Point2
Set point_ref12 = part1.CreateReferenceFromObject(Point2)
Dim Ref3 As Reference
Set Ref3 = part1.CreateReferenceFromObject(HybridShapeExtremum3)
Dim Point3 As HybridShapePointCoord
Set Point3 = hybridShapeFactory1.AddNewPointCoordWithReference(0, 0, 0, Ref3)
hybridBody2.AppendHybridShape Point3
Set point_ref13 = part1.CreateReferenceFromObject(Point3)
Dim Ref4 As Reference
Set Ref4 = part1.CreateReferenceFromObject(HybridShapeExtremum4)
Dim Point4 As HybridShapePointCoord
Set Point4 = hybridShapeFactory1.AddNewPointCoordWithReference(0, 0, 0, Ref4)
hybridBody2.AppendHybridShape Point4
Set point_ref14 = part1.CreateReferenceFromObject(Point4)
Dim Ref5 As Reference
Set Ref5 = part1.CreateReferenceFromObject(HybridShapeExtremum5)
Dim Point5 As HybridShapePointCoord
Set Point5 = hybridShapeFactory1.AddNewPointCoordWithReference(0, 0, 0, Ref5)
hybridBody2.AppendHybridShape Point5
Set point_ref5 = part1.CreateReferenceFromObject(Point5)
Dim Ref6 As Reference
Set Ref6 = part1.CreateReferenceFromObject(HybridShapeExtremum6)
Dim Point6 As HybridShapePointCoord
Set Point6 = hybridShapeFactory1.AddNewPointCoordWithReference(0, 0, 0, Ref6)
hybridBody2.AppendHybridShape Point6
Set point_ref6 = part1.CreateReferenceFromObject(Point6)
part1.Update
axissyst.IsCurrent = 1
'Create a sketch, will the the X and Y boundary
Set sketches1 = hybridBody1.HybridSketches
Set reference_axis_syst = part1.CreateReferenceFromName("Selection_RSur:(Face:(Brp:(BBoxAxis;1);None:());BBoxAxis)")
Set standard_body_sketch1 = sketches1.Add(reference_axis_syst)
Set factory2D1 = standard_body_sketch1.OpenEdition()
Set geometricElements1 = standard_body_sketch1.GeometricElements
Set axis2D1 = geometricElements1.Item("AbsoluteAxis")
Set line_HDirection = axis2D1.GetItem("HDirection")
line_HDirection.ReportName = 1
Set line_VDirection = axis2D1.GetItem("VDirection")
line_VDirection.ReportName = 2
' Creates a square in the sketch
ponto = 20000
Set point_ref_1 = factory2D1.CreatePoint(-ponto, -ponto)
point_ref_1.ReportName = 3
Set point_ref_2 = factory2D1.CreatePoint(ponto, -ponto)
point_ref_2.ReportName = 4
Set point_ref_3 = factory2D1.CreatePoint(ponto, ponto)
point_ref_3.ReportName = 5
Set point_ref_4 = factory2D1.CreatePoint(-ponto, ponto)
point_ref_4.ReportName = 6
Set line_ref_1_2 = factory2D1.CreateLine(-ponto, -ponto, ponto, -ponto)
line_ref_1_2.ReportName = 7
line_ref_1_2.StartPoint = point_ref_1
line_ref_1_2.EndPoint = point_ref_2
Set line_ref_2_3 = factory2D1.CreateLine(ponto, -ponto, ponto, ponto)
line_ref_2_3.ReportName = 8
line_ref_2_3.StartPoint = point_ref_2
line_ref_2_3.EndPoint = point_ref_3
Set line_ref_3_4 = factory2D1.CreateLine(-ponto, ponto, ponto, ponto)
line_ref_3_4.ReportName = 9
line_ref_3_4.StartPoint = point_ref_4
line_ref_3_4.EndPoint = point_ref_3
Set line_ref_4_1 = factory2D1.CreateLine(-ponto, -ponto, -ponto, ponto)
line_ref_4_1.ReportName = 10
'line_ref_4_1.Construction = True
line_ref_4_1.StartPoint = point_ref_1
line_ref_4_1.EndPoint = point_ref_4
' Create Reference lines and constraints
Set reference_line_ref_1_2 = part1.CreateReferenceFromObject(line_ref_1_2)
Set reference_line_ref_2_3 = part1.CreateReferenceFromObject(line_ref_2_3)
Set reference_line_ref_3_4 = part1.CreateReferenceFromObject(line_ref_3_4)
Set reference_line_ref_4_1 = part1.CreateReferenceFromObject(line_ref_4_1)
Set electrode_constraints = standard_body_sketch1.Constraints
Set constraint_toto_2 = electrode_constraints.AddBiEltCst(catCstTypeDistance, point_ref11, reference_line_ref_2_3)
Set constraint_toto_3 = electrode_constraints.AddBiEltCst(catCstTypeDistance, point_ref13, reference_line_ref_3_4)
Set constraint_toto_4 = electrode_constraints.AddBiEltCst(catCstTypeDistance, reference_line_ref_4_1, point_ref12)
Set constraint_toto_1 = electrode_constraints.AddBiEltCst(catCstTypeDistance, reference_line_ref_1_2, point_ref14)
Dim length1 As Dimension
Set length1 = constraint_toto_1.Dimension
length1.Value = 0
Dim length2 As Dimension
Set length2 = constraint_toto_2.Dimension
length2.Value = 0
Dim length3 As Dimension
Set length3 = constraint_toto_3.Dimension
length3.Value = 0
Dim length4 As Dimension
Set length4 = constraint_toto_4.Dimension
length4.Value = 0
standard_body_sketch1.CloseEdition
part1.Update
'----------------------------------------------------------------------------------------------------------------------------------
' Creation of the Max Z and Min Z planes
'----------------------------------------------------------------------------------------------------------------------------------
Dim plan_inferieur As HybridShapePlaneOffsetPt
Dim plan_origin As HybridShapePlane2Lines
Dim Origin_line_1 As Reference
Set Origin_line_1 = part1.CreateReferenceFromObject(line_HDirection)
Dim Origin_line_2 As Reference
Set Origin_line_2 = part1.CreateReferenceFromObject(line_VDirection)
Set plan_origin = hybridShapeFactory1.AddNewPlane2Lines(Origin_line_1, Origin_line_2)
Dim ref_plan_origin As Reference
Set ref_plan_origin = part1.CreateReferenceFromObject(plan_origin)
Set Ref6 = part1.CreateReferenceFromObject(HybridShapeExtremum6)
Set plan_inferieur = hybridShapeFactory1.AddNewPlaneOffsetPt(ref_plan_origin, point_ref6)
hybridBody2.AppendHybridShape plan_inferieur
part1.InWorkObject = plan_inferieur
Dim plan_superieur As HybridShapePlaneOffsetPt
Set Ref5 = part1.CreateReferenceFromObject(HybridShapeExtremum5)
Set plan_superieur = hybridShapeFactory1.AddNewPlaneOffsetPt(ref_plan_origin, point_ref5)
hybridBody2.AppendHybridShape plan_superieur
part1.InWorkObject = plan_superieur
part1.Update
'----------------------------------------------------------------------------------------------------------------------------------
' Creates the line that sweeps around the XY Sketch boundary
'----------------------------------------------------------------------------------------------------------------------------------
Dim Point_inf As HybridShapePointCoord
Set Point_inf = hybridShapeFactory1.AddNewPointCoordWithReference(0, 0, 0, point_ref6)
hybridBody2.AppendHybridShape Point_inf
Dim ref_point_inf As Reference
Set ref_point_inf = part1.CreateReferenceFromObject(Point_inf)
Dim proj_pt_inf As HybridShapeProject
Set proj_pt_inf = hybridShapeFactory1.AddNewProject(point_ref6, plan_superieur)
hybridBody2.AppendHybridShape proj_pt_inf
part1.InWorkObject = proj_pt_inf
Dim Point_sup As HybridShapePointCoord
Set Point_sup = hybridShapeFactory1.AddNewPointCoordWithReference(0, 0, 0, proj_pt_inf)
hybridBody2.AppendHybridShape Point_sup
Dim ref_point_sup As Reference
Set ref_point_sup = part1.CreateReferenceFromObject(Point_sup)
Dim line_guide As HybridShapeLinePtPt
Set line_guide = hybridShapeFactory1.AddNewLinePtPt(ref_point_sup, ref_point_inf)
hybridBody2.AppendHybridShape line_guide
part1.InWorkObject = line_guide
Set ref_guideline = part1.CreateReferenceFromObject(line_guide)
Dim oStart As Length
Set oStart = line_guide.BeginOffset
oStart.Value = 1
Dim oEnd As Length
Set oEnd = line_guide.EndOffset
oEnd.Value = 1
Set constraints_for_z = part1.Constraints
Set constraint_dz = constraints_for_z.AddMonoEltCst(catCstTypeLength, ref_guideline)
Set length_dz = constraint_dz.Dimension
part1.Update
'----------------------------------------------------------------------------------------------------------------------------------
' Second Sketch, basically the XY boundary sketch placed down to Min Z
'----------------------------------------------------------------------------------------------------------------------------------
Set sketches2 = hybridBody1.HybridSketches
Set standard_body_sketch2 = sketches2.Add(plan_inferieur)
Set factory2D2 = standard_body_sketch2.OpenEdition()
Set geometricElements2 = standard_body_sketch2.GeometricElements
Set axis2D1 = geometricElements1.Item("AbsoluteAxis")
pont = 200000
Set point_ref1_1 = factory2D2.CreatePoint(-pont, -pont)
Set point_ref1_2 = factory2D2.CreatePoint(pont, -pont)
Set point_ref1_3 = factory2D2.CreatePoint(pont, pont)
Set point_ref1_4 = factory2D2.CreatePoint(-pont, pont)
Set line_ref1_1_2 = factory2D2.CreateLine(-pont, -pont, pont, -pont)
line_ref1_1_2.StartPoint = point_ref1_1
line_ref1_1_2.EndPoint = point_ref1_2
Set line_ref1_2_3 = factory2D2.CreateLine(pont, -pont, pont, pont)
line_ref1_2_3.StartPoint = point_ref1_2
line_ref1_2_3.EndPoint = point_ref1_3
Set line_ref1_3_4 = factory2D2.CreateLine(-pont, pont, pont, pont)
line_ref1_3_4.StartPoint = point_ref1_4
line_ref1_3_4.EndPoint = point_ref1_3
Set line_ref1_4_1 = factory2D2.CreateLine(-pont, -pont, -pont, pont)
line_ref1_4_1.StartPoint = point_ref1_1
line_ref1_4_1.EndPoint = point_ref1_4
Set reference_line_ref1_1_2 = part1.CreateReferenceFromObject(line_ref1_1_2)
Set reference_line_ref1_2_3 = part1.CreateReferenceFromObject(line_ref1_2_3)
Set reference_line_ref1_3_4 = part1.CreateReferenceFromObject(line_ref1_3_4)
Set reference_line_ref1_4_1 = part1.CreateReferenceFromObject(line_ref1_4_1)
Set reference_line_ref_1_2 = part1.CreateReferenceFromObject(line_ref_1_2)
Set reference_line_ref_2_3 = part1.CreateReferenceFromObject(line_ref_2_3)
Set reference_line_ref_3_4 = part1.CreateReferenceFromObject(line_ref_3_4)
Set reference_line_ref_4_1 = part1.CreateReferenceFromObject(line_ref_4_1)
Set proj_1_2 = factory2D2.CreateProjection(reference_line_ref_1_2)
Set proj_2_3 = factory2D2.CreateProjection(reference_line_ref_2_3)
Set proj_3_4 = factory2D2.CreateProjection(reference_line_ref_3_4)
Set proj_4_1 = factory2D2.CreateProjection(reference_line_ref_4_1)
Set ref_line_sk1_1_2 = part1.CreateReferenceFromObject(proj_1_2)
Set ref_line_sk1_2_3 = part1.CreateReferenceFromObject(proj_2_3)
Set ref_line_sk1_3_4 = part1.CreateReferenceFromObject(proj_3_4)
Set ref_line_sk1_4_1 = part1.CreateReferenceFromObject(proj_4_1)
Set electrode_constraints = standard_body_sketch2.Constraints
Set constraint_toto_11 = electrode_constraints.AddBiEltCst(catCstTypeDistance, reference_line_ref1_1_2, ref_line_sk1_1_2)
Set constraint_toto_12 = electrode_constraints.AddBiEltCst(catCstTypeDistance, ref_line_sk1_2_3, reference_line_ref1_2_3)
Set constraint_toto_13 = electrode_constraints.AddBiEltCst(catCstTypeDistance, ref_line_sk1_3_4, reference_line_ref1_3_4)
Set constraint_toto_14 = electrode_constraints.AddBiEltCst(catCstTypeDistance, reference_line_ref1_4_1, ref_line_sk1_4_1)
'Dim length11 As Dimension
Set length11 = constraint_toto_11.Dimension
length11.Value = 1
Dim length12 As Dimension
Set length12 = constraint_toto_12.Dimension
length12.Value = 1
Dim length13 As Dimension
Set length13 = constraint_toto_13.Dimension
length13.Value = 1
Dim length14 As Dimension
Set length14 = constraint_toto_14.Dimension
length14.Value = 1
standard_body_sketch2.CloseEdition
part1.Update
'----------------------------------------------------------------------------------------------------------------------------------
' Offset from Sketch2, using the Relations so you can change the offsets
'----------------------------------------------------------------------------------------------------------------------------------
Set sketches3 = hybridBody1.HybridSketches
Set standard_body_sketch3 = sketches3.Add(plan_inferieur)
Set factory2D3 = standard_body_sketch3.OpenEdition()
Set geometricElements3 = standard_body_sketch3.GeometricElements
Set axis2D1 = geometricElements1.Item("AbsoluteAxis")
Set reference_line_ref1_1_2 = part1.CreateReferenceFromObject(line_ref1_1_2)
Set reference_line_ref1_2_3 = part1.CreateReferenceFromObject(line_ref1_2_3)
Set reference_line_ref1_3_4 = part1.CreateReferenceFromObject(line_ref1_3_4)
Set reference_line_ref1_4_1 = part1.CreateReferenceFromObject(line_ref1_4_1)
Set proj1_1_2 = factory2D3.CreateProjection(reference_line_ref1_1_2)
Set proj1_2_3 = factory2D3.CreateProjection(reference_line_ref1_2_3)
Set proj1_3_4 = factory2D3.CreateProjection(reference_line_ref1_3_4)
Set proj1_4_1 = factory2D3.CreateProjection(reference_line_ref1_4_1)
Set ref_proj1_1_2 = part1.CreateReferenceFromObject(proj1_1_2)
Set ref_proj1_2_3 = part1.CreateReferenceFromObject(proj1_2_3)
Set ref_proj1_3_4 = part1.CreateReferenceFromObject(proj1_3_4)
Set ref_proj1_4_1 = part1.CreateReferenceFromObject(proj1_4_1)
Set constraints_dim = standard_body_sketch3.Constraints
Set constraint_dx = constraints_dim.AddMonoEltCst(catCstTypeLength, ref_proj1_1_2)
Set constraint_dy = constraints_dim.AddMonoEltCst(catCstTypeLength, ref_proj1_2_3)
Set length_dx = constraint_dx.Dimension
dx_value = length_dx.Value
Set length_dy = constraint_dy.Dimension
dy_value = length_dy.Value
standard_body_sketch3.CloseEdition
part1.Update
' Create the offset parameters
Dim string_1 As String
string_1 = "Offset_Bbox_Max_X." & j
Dim string_2 As String
string_2 = "Offset_Bbox_Min_X." & j
Dim string_3 As String
string_3 = "Offset_Bbox_Max_Y." & j
Dim string_4 As String
string_4 = "Offset_Bbox_Min_Y." & j
Dim string_5 As String
string_5 = "Offset_Bbox_Max_Z." & j
Dim string_6 As String
string_6 = "Offset_Bbox_Min_Z." & j
Dim string_7 As String
string_7 = "Bbox_dx." & j
Dim string_8 As String
string_8 = "Bbox_dy." & j
Dim string_9 As String
string_9 = "Bbox_dz." & j
Dim Offset_Bbox_Max_X As RealParam
Set Offset_Bbox_Max_X = part1.Parameters.CreateDimension(string_1, "Length", 0)
Dim Offset_Bbox_Min_X As RealParam
Set Offset_Bbox_Min_X = part1.Parameters.CreateDimension(string_2, "Length", 0)
Dim Offset_Bbox_Max_Y As RealParam
Set Offset_Bbox_Max_Y = part1.Parameters.CreateDimension(string_3, "Length", 0)
Dim Offset_Bbox_Min_Y As RealParam
Set Offset_Bbox_Min_Y = part1.Parameters.CreateDimension(string_4, "Length", 0)
Dim Offset_Bbox_Max_Z As RealParam
Set Offset_Bbox_Max_Z = part1.Parameters.CreateDimension(string_5, "Length", 0)
Dim Offset_Bbox_Min_Z As RealParam
Set Offset_Bbox_Min_Z = part1.Parameters.CreateDimension(string_6, "Length", 0)
Set Bbox_dx_hidden = part1.Parameters.CreateDimension(string_7, "Length", dx_value)
Set Bbox_dy_hidden = part1.Parameters.CreateDimension(string_8, "Length", dy_value)
Set Bbox_dz_hidden = part1.Parameters.CreateDimension(string_9, "Length", length_dz.Value)
Bbox_dx_hidden.Hidden = True
Bbox_dy_hidden.Hidden = True
Bbox_dz_hidden.Hidden = True
Set Bbox_dx = part1.Parameters.CreateDimension(string_7, "Length", 0)
Set Bbox_dy = part1.Parameters.CreateDimension(string_8, "Length", 0)
Set Bbox_dz = part1.Parameters.CreateDimension(string_9, "Length", 0)
Dim Formula_1 As Formula
Set Formula_1 = part1.Relations.CreateFormula("formula_Bbox_1." & j, "", length14, "Offset_Bbox_Min_X." & j)
Dim Formula_2 As Formula
Set Formula_2 = part1.Relations.CreateFormula("formula_Bbox_2." & j, "", length12, "Offset_Bbox_Max_X." & j)
Dim Formula_3 As Formula
Set Formula_3 = part1.Relations.CreateFormula("formula_Bbox_4." & j, "", length11, "Offset_Bbox_Min_Y." & j)
Dim Formula_4 As Formula
Set Formula_4 = part1.Relations.CreateFormula("formula_Bbox_4." & j, "", length13, "Offset_Bbox_Max_Y." & j)
Dim Formula_5 As Formula
Set Formula_5 = part1.Relations.CreateFormula("formula_Bbox_5." & j, "", oEnd, " Offset_Bbox_Min_Z." & j)
Dim Formula_6 As Formula
Set Formula_6 = part1.Relations.CreateFormula("formula_Bbox_6." & j, "", oStart, " Offset_Bbox_Max_Z." & j)
Dim Formula_7 As Formula
Set Formula_7 = part1.Relations.CreateFormula("formula_Bbox_7." & j, "", Bbox_dx, "Bbox_dx." & j & "+Offset_Bbox_Min_X." & j & "+Offset_Bbox_Max_X." & j & "-2mm")
Dim Formula_8 As Formula
Set Formula_8 = part1.Relations.CreateFormula("formula_Bbox_8." & j, "", Bbox_dy, "Bbox_dy." & j & "+Offset_Bbox_Min_Y." & j & "+Offset_Bbox_Max_Y." & j & "-2mm")
Dim Formula_9 As Formula
Set Formula_9 = part1.Relations.CreateFormula("formula_Bbox_9." & j, "", Bbox_dz, "Bbox_dz." & j & "+Offset_Bbox_Min_Z." & j & "+Offset_Bbox_Max_Z." & j & "-2mm")
'----------------------------------------------------------------------------------------------------------------------------------
' Sweep the Z line around the XY boundary. This will be closed
'----------------------------------------------------------------------------------------------------------------------------------
Set sweepref_1 = part1.CreateReferenceFromObject(standard_body_sketch3)
Set guide1 = part1.CreateReferenceFromObject(line_guide)
Dim sweep1 As HybridShapeSweepExplicit
Set sweep1 = hybridShapeFactory1.AddNewSweepExplicit(sweepref_1, guide1)
hybridBody2.AppendHybridShape sweep1
part1.InWorkObject = sweep1
part1.Update
' Close the Sweep
Set shapeFactory1 = part1.ShapeFactory
Set hybridBodies1 = body1.HybridBodies
Set hybridBody1 = hybridBodies1.Item("definition_points")
Dim hybridShapes1 As HybridShapes
Set hybridShapes1 = hybridBody1.HybridShapes
Dim refer1 As Reference
Set refer1 = part1.CreateReferenceFromObject(sweep1)
Dim closeSurface1 As CloseSurface
Set closeSurface1 = shapeFactory1.AddNewCloseSurface(refer1)
closeSurface1.Name = "BoundingBox"
part1.Update
selection.Clear
selection.Add hybridBody1
selection.VisProperties.SetShow catVisPropertyNoShowAttr
selection.Clear
selection.Add body1
selection.VisProperties.SetRealColor 0, 0, 0, 0
selection.VisProperties.SetRealOpacity 150, 1
selection.VisProperties.SetRealWidth 2, 1
part1.Update
axissyst.Name = "Bounding Box Axis." & j
Else
MsgBox "The active document must be a CATPart"
End If
End If
End Sub