New Bounding Box issue
New Bounding Box issue
(OP)
Hello,
I created the Bounding Box macro from the Portable Script Center.
When I try to run it on a part, i click the axis it creates, i click a plane, and it begins to run.
It creates a bunch of geometry and then fails.
Here is the failure notification:
Execute the script "BoundingBox.CATScript".
The scripting engine for CATScript has reported the following error:
Source: CATIAPart
Description: The method Update Failed
Line:609
Column:16
See the language reference guide or the V5 Automation APIs documentation.
Line: 609 shows: par1.update.
Does anybody know what is going on or what I can do to fix this?





RE: New Bounding Box issue
Which CATIA release, what operating system, 32 or 64 bit ? You said is a CATScript, correct? What kind of CATPart is it? Is it Enable Hybrid Design mode or not?
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: New Bounding Box issue
It is the CATScript out of the Portable Script Center.
Hybrid design is disabled.
Its fairly simple part.
RE: New Bounding Box issue
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: New Bounding Box issue
CODE --> CATScript
'---------------------------------------------------------------------------------------------------------------------------------- 'creation sweep '---------------------------------------------------------------------------------------------------------------------------------- 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.updateRE: New Bounding Box issue
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: New Bounding Box issue
you have to adopt it to vba...sorry trying to stay out of CatScript
CODE --> vb6
Private Sub OkAndExit_Click() Me.Hide 'Get CATIA or Launch it if necessary. On Error Resume Next Set MyCATIA = GetObject(, "CATIA.Application") If Err.Number <> 0 Then Set MyCATIA = CreateObject("CATIA.Application") MyCATIA.Visible = False End If On Error GoTo 0 'Make sure they have axis ready and want to start MyCATIA.DisplayFileAlerts = False Dim Message, Style, Title, Response, MyString Message = ("PRESS OK AND SELECT AXIS SYSTEM" & _ (Chr(13)) & _ "THE AXIS SYSTEM MUST BE BASED ON TOOLING DIRECTION") 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 = MyCATIA.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 = MyCATIA.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 Unload BoundingBox End SubRE: New Bounding Box issue
How do I Adapt the VB6 code you provided to VBA?
I have no preference over any of the codes, as long as I can get them to work.
RE: New Bounding Box issue
CODE --> vba
Sub CATMain() 'Make sure they have axis ready and want to start CATIA.DisplayFileAlerts = False Dim Message, Style, Title, Response, MyString Message = ("PRESS OK AND SELECT AXIS SYSTEM" & _ (Chr(13)) & _ "THE AXIS SYSTEM MUST BE BASED ON TOOLING DIRECTION") 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 Subwork around on message boxes
RE: New Bounding Box issue
The Macro will run, but some of my parts are very complex with no straight edges to create an axis off of.
When I try to run the Macro off of the axis i created, i get a bounding box that is nothing like my part.
Any advice on how to attack this problem?
RE: New Bounding Box issue
There are a lot of threads about this subject, you can search the forum, the rough stock command is working like Measure Inertia command and this is not always the best choice, the volume created is not always the minimum (hope you are looking for this solution and not something else).
With the macro, depending on how you choose the axis, you can have a smaller volume then measure inertia, especially for complex parts (I just notice that you have to create the axis first)
All what you have to do is to compare the volume resulting from BBLx * BBLy * BBLz for both solutions.
The best example which I had are parts done with sheet metal design license. If you want the bounding box for an unfolded part you have to obtain the minimum area (BBLx * BBLy , for example) which for sure you will not obtain every time with measure inertia command.
It would be great if you could post here a sample dumb part to see what you want in fact. Anyway, hope the pictures attached are good enough to explain what was going on.
JeniaL, star from me for your work.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: New Bounding Box issue
he bounding box action also can be recorded with macro recorder. extremum point command should be used. axis system must be defined before.
@ jzecha upload catia file.. this macro works pretty well with very complex shapes.