Continue to Site

Welcome to MCAD Central

Join our MCAD Central community forums, the largest resource for MCAD (Mechanical Computer-Aided Design) professionals, including files, forums, jobs, articles, calendar, and more.

i have a doubt in macros of catia

Nandhakumar

New member
I encountered a problem while running the macros. what happened is:
I opened catia and from macros option, i select start recording. In part design, i am drawing a block (cube). then i stop recording and opened that macro, the same block is coming. But, if i tried the same thing for a block with rectangular or circular pattern, it shows error in running that macro. the error shown is “Set hybridShapeLineExplicit1 = hybridShapes1.Item(“X Axis”)”. can you please help me in rectifying that error, it will be useful for my project.
thank you. the full code is given below:
Language="VBSCRIPT"

Sub CATMain()

Set documents1 = CATIA.Documents

Set partDocument1 = documents1.Add("Part")

Set part1 = partDocument1.Part

Set bodies1 = part1.Bodies

Set body1 = bodies1.Item("PartBody")

Set sketches1 = body1.Sketches

Set originElements1 = part1.OriginElements

Set reference1 = originElements1.PlaneYZ

Set sketch1 = sketches1.Add(reference1)

Dim arrayOfVariantOfDouble1(8)
arrayOfVariantOfDouble1(0) = 0.000000
arrayOfVariantOfDouble1(1) = 0.000000
arrayOfVariantOfDouble1(2) = 0.000000
arrayOfVariantOfDouble1(3) = 0.000000
arrayOfVariantOfDouble1(4) = 1.000000
arrayOfVariantOfDouble1(5) = 0.000000
arrayOfVariantOfDouble1(6) = 0.000000
arrayOfVariantOfDouble1(7) = 0.000000
arrayOfVariantOfDouble1(8) = 1.000000
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(-8.844769, 69.496485)

point2D1.ReportName = 3

Set point2D2 = factory2D1.CreatePoint(20.637792, 69.496485)

point2D2.ReportName = 4

Set line2D3 = factory2D1.CreateLine(-8.844769, 69.496485, 20.637792, 69.496485)

line2D3.ReportName = 5

line2D3.StartPoint = point2D1

line2D3.EndPoint = point2D2

Set point2D3 = factory2D1.CreatePoint(20.637792, 40.855509)

point2D3.ReportName = 6

Set line2D4 = factory2D1.CreateLine(20.637792, 69.496485, 20.637792, 40.855509)

line2D4.ReportName = 7

line2D4.EndPoint = point2D2

line2D4.StartPoint = point2D3

Set point2D4 = factory2D1.CreatePoint(-8.844769, 40.855509)

point2D4.ReportName = 8

Set line2D5 = factory2D1.CreateLine(20.637792, 40.855509, -8.844769, 40.855509)

line2D5.ReportName = 9

line2D5.StartPoint = point2D3

line2D5.EndPoint = point2D4

Set line2D6 = factory2D1.CreateLine(-8.844769, 40.855509, -8.844769, 69.496485)

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 = body1

part1.Update

part1.InWorkObject = body1

Set shapeFactory1 = part1.ShapeFactory

Set pad1 = shapeFactory1.AddNewPad(sketch1, 20.000000)

part1.Update

Set reference10 = part1.CreateReferenceFromName("")

Set reference11 = part1.CreateReferenceFromName("")

Set circPattern1 = shapeFactory1.AddNewCircPattern(pad1, 1, 2, 20.000000, 45.000000, 1, 1, reference10, reference11, True, 0.000000, True)

circPattern1.CircularPatternParameters = catInstancesandAngularSpacing

circPattern1.CircularPatternParameters = catCompleteCrown

Set angularRepartition1 = circPattern1.AngularRepartition

Set angle1 = angularRepartition1.AngularSpacing

angle1.Value = 180.000000

Set angularRepartition2 = circPattern1.AngularRepartition

Set intParam1 = angularRepartition2.InstancesCount

intParam1.Value = 2

intParam1.Value = 5

Set hybridBodies1 = part1.HybridBodies

Set hybridBody1 = hybridBodies1.Add()

Set hybridShapes1 = hybridBody1.HybridShapes

Set hybridShapeLineExplicit1 = hybridShapes1.Item("X Axis")

Set reference12 = part1.CreateReferenceFromObject(hybridShapeLineExplicit1)

circPattern1.SetRotationAxis reference12

part1.Update

End Sub
 
@Nandhakumar
Your code is telling CATIA to look for an axis called "X Axis" in order to complete the rotation feature. This axis must either already be in your part - or - your macro can create it by simply creating a line and telling the circle pattern to use that instead of "X Axis". See attached for what the script is looking for, but if your script creates a new part each time, then it's not going to find it.
xaxis.jpg
 
@Nandhakumar
Your code is telling CATIA to look for an axis called "X Axis" in order to complete the rotation feature. This axis must either already be in your part - or - your macro can create it by simply creating a line and telling the circle pattern to use that instead of "X Axis". See attached for what the script is looking for, but if your script creates a new part each time, then it's not going to find it.
axis.jpg
 

Sponsor

Back
Top