Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with renaming a feature while executing a macro.

Status
Not open for further replies.

Kalasalbin

Mechanical
Jul 3, 2018
4
SE
Hello. I'm new to this forum and need som help with programming a macro in Catia. What the macro does is that it splits a beam so that the middle part is left and then measures the clearence between surrounding components. My problem is that I can't predict which number my new split will have so that the following measurements wont work. If anyone can help me to insert some code that will rename my split into something of my choosing I would really appreciate it. I will highlight where the split is made in the code where I also want the renaming of the split feature. Thanks!



Language="VBSCRIPT"

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set hybridBodies1 = part1.HybridBodies

Set hybridBody1 = hybridBodies1.Item("check")

Set sketches1 = hybridBody1.HybridSketches

Set reference1 = part1.CreateReferenceFromName("Selection_RSur:(Face:(Brp:(Axis_00;3);None:();Cf11:());Axis_00;Z0;G6284)")

Set sketch1 = sketches1.Add(reference1)

Dim arrayOfVariantOfDouble1(8)
arrayOfVariantOfDouble1(0) = 2756.976947
arrayOfVariantOfDouble1(1) = -880.902000
arrayOfVariantOfDouble1(2) = 1075.486315
arrayOfVariantOfDouble1(3) = 0.366938
arrayOfVariantOfDouble1(4) = 0.000000
arrayOfVariantOfDouble1(5) = 0.930245
arrayOfVariantOfDouble1(6) = -0.928970
arrayOfVariantOfDouble1(7) = -0.052336
arrayOfVariantOfDouble1(8) = 0.366435
sketch1.SetAbsoluteAxisData arrayOfVariantOfDouble1

part1.InWorkObject = sketch1

Set factory2D1 = sketch1.OpenEdition()

Set geometricElements1 = sketch1.GeometricElements

Set axis2D1 = geometricElements1.Item("AbsoluteAxis")

Set line2D1 = axis2D1.GetItem("HDirection")

line2D1.ReportName = 1

Set line2D2 = axis2D1.GetItem("VDirection")

line2D2.ReportName = 2

Set point2D1 = factory2D1.CreatePoint(-67.145811, 281.008170)

point2D1.ReportName = 3

Set point2D2 = factory2D1.CreatePoint(75.628087, 281.008170)

point2D2.ReportName = 4

Set line2D3 = factory2D1.CreateLine(-67.145811, 281.008170, 75.628087, 281.008170)

line2D3.ReportName = 5

line2D3.StartPoint = point2D1

line2D3.EndPoint = point2D2

Set point2D3 = factory2D1.CreatePoint(75.628087, -233.073526)

point2D3.ReportName = 6

Set line2D4 = factory2D1.CreateLine(75.628087, 281.008170, 75.628087, -233.073526)

line2D4.ReportName = 7

line2D4.EndPoint = point2D2

line2D4.StartPoint = point2D3

Set point2D4 = factory2D1.CreatePoint(-67.145811, -233.073526)

point2D4.ReportName = 8

Set line2D5 = factory2D1.CreateLine(75.628087, -233.073526, -67.145811, -233.073526)

line2D5.ReportName = 9

line2D5.StartPoint = point2D3

line2D5.EndPoint = point2D4

Set line2D6 = factory2D1.CreateLine(-67.145811, -233.073526, -67.145811, 281.008170)

line2D6.ReportName = 10

line2D6.EndPoint = point2D4

line2D6.StartPoint = point2D1

Set constraints1 = sketch1.Constraints

Set reference2 = part1.CreateReferenceFromObject(line2D3)

Set reference3 = part1.CreateReferenceFromObject(line2D1)

Set constraint1 = constraints1.AddBiEltCst(catCstTypeHorizontality, reference2, reference3)

constraint1.Mode = catCstModeDrivingDimension

Set reference4 = part1.CreateReferenceFromObject(line2D5)

Set reference5 = part1.CreateReferenceFromObject(line2D1)

Set constraint2 = constraints1.AddBiEltCst(catCstTypeHorizontality, reference4, reference5)

constraint2.Mode = catCstModeDrivingDimension

Set reference6 = part1.CreateReferenceFromObject(line2D4)

Set reference7 = part1.CreateReferenceFromObject(line2D2)

Set constraint3 = constraints1.AddBiEltCst(catCstTypeVerticality, reference6, reference7)

constraint3.Mode = catCstModeDrivingDimension

Set reference8 = part1.CreateReferenceFromObject(line2D6)

Set reference9 = part1.CreateReferenceFromObject(line2D2)

Set constraint4 = constraints1.AddBiEltCst(catCstTypeVerticality, reference8, reference9)

constraint4.Mode = catCstModeDrivingDimension

sketch1.CloseEdition

part1.InWorkObject = hybridBody1

part1.Update

Set hybridShapeFactory1 = part1.HybridShapeFactory

Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(0.000000, 0.000000, 0.000000)

Set reference10 = part1.CreateReferenceFromObject(sketch1)

Set hybridShapeExtrude1 = hybridShapeFactory1.AddNewExtrude(reference10, -150.000000, -168.000000, hybridShapeDirection1)

hybridShapeExtrude1.SymmetricalExtension = 0

hybridBody1.AppendHybridShape hybridShapeExtrude1

part1.InWorkObject = hybridShapeExtrude1

part1.Update

Set bodies1 = part1.Bodies

Set body1 = bodies1.Item("PartBody")

Set shapes1 = body1.Shapes

Set reference11 = shapes1.Item("beam_solid")

Set reference12 = part1.CreateReferenceFromObject(hybridShapeExtrude1)

[highlight #FCE94F]Set hybridShapeSplit1 = hybridShapeFactory1.AddNewHybridSplit(reference11, reference12, -1)

hybridShapeFactory1.GSMVisibility reference11, 0

hybridShapeSplit1.ExtrapolationType = 1

hybridBody1.AppendHybridShape hybridShapeSplit1

part1.InWorkObject = hybridShapeSplit1[/highlight]

part1.Update

part1.Update

Set selection1 = partDocument1.Selection

Set visPropertySet1 = selection1.VisProperties

Set hybridShapes1 = hybridShapeExtrude1.Parent

Dim bSTR1
bSTR1 = hybridShapeExtrude1.Name

selection1.Add hybridShapeExtrude1

Set visPropertySet1 = visPropertySet1.Parent

Dim bSTR2
bSTR2 = visPropertySet1.Name

Dim bSTR3
bSTR3 = visPropertySet1.Name

visPropertySet1.SetShow 1

selection1.Clear

Set selection2 = partDocument1.Selection

Set visPropertySet2 = selection2.VisProperties

Set sketches1 = sketch1.Parent

Dim bSTR4
bSTR4 = sketch1.Name

selection2.Add sketch1

Set visPropertySet2 = visPropertySet2.Parent

Dim bSTR5
bSTR5 = visPropertySet2.Name

Dim bSTR6
bSTR6 = visPropertySet2.Name

visPropertySet2.SetShow 1

selection2.Clear

Set selection3 = partDocument1.Selection

Set visPropertySet3 = selection3.VisProperties

Set thickSurface1 = shapes1.Item("beam_solid")

Set shapes1 = thickSurface1.Parent

Dim bSTR7
bSTR7 = thickSurface1.Name

selection3.Add thickSurface1

Set visPropertySet3 = visPropertySet3.Parent

Dim bSTR8
bSTR8 = visPropertySet3.Name

Dim bSTR9
bSTR9 = visPropertySet3.Name

visPropertySet3.SetShow 1

selection3.Clear

Set selection4 = partDocument1.Selection

Set visPropertySet4 = selection4.VisProperties

Set axisSystems1 = part1.AxisSystems

Set axisSystem1 = axisSystems1.Item("Axis_00")

Set axisSystems1 = axisSystem1.Parent

Dim bSTR10
bSTR10 = axisSystem1.Name

selection4.Add axisSystem1

Set visPropertySet4 = visPropertySet4.Parent

Dim bSTR11
bSTR11 = visPropertySet4.Name

Dim bSTR12
bSTR12 = visPropertySet4.Name

visPropertySet4.SetShow 1

selection4.Clear

Set specsAndGeomWindow1 = CATIA.ActiveWindow

Set viewer3D1 = specsAndGeomWindow1.ActiveViewer

Set viewpoint3D1 = viewer3D1.Viewpoint3D

Set parameters1 = part1.Parameters

Set length1 = parameters1.CreateDimension("", "LENGTH", 0.000000)

Set relations1 = part1.Relations

Set formula1 = relations1.CreateFormula("Formula.2921", "", length1, "distance(check\Split.55 ,check\window )")

formula1.Rename "Formula.2921"

Set parameters2 = part1.Parameters

Set length2 = parameters2.CreateDimension("", "LENGTH", 0.000000)

Set relations2 = part1.Relations

Set formula2 = relations2.CreateFormula("Formula.2922", "", length2, "distance(check\Split.55 ,check\door ) ")

formula2.Rename "Formula.2922"

Set parameters3 = part1.Parameters

Set length3 = parameters3.CreateDimension("", "LENGTH", 0.000000)

Set relations3 = part1.Relations

Set formula3 = relations3.CreateFormula("Formula.2923", "", length3, "distance(check\Split.55 ,check\brackets ) ")

formula3.Rename "Formula.2923"

length3.Rename "beam_brackets"

length2.Rename "beam_door"

length1.Rename "beam_window"

part1.Update

End Sub
 
Replies continue below

Recommended for you

Hi.

It seems that you can turn things other way around - use generated name in formulas:

Set formula1 = relations1.CreateFormula("Formula.2921", "", length1, "distance(check\" + hybridShapeSplit1.Name + " ,check\window )")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top