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!

Catia V5 Shaft Script

Status
Not open for further replies.

Arun_Gopala

New member
Apr 20, 2020
7
US
Dear All
I have recorded editing shaft First angle macro in CATIA V 5-6 R2017 and then I tried to run it it gives me an error saying
The Method Dimension failed
Line: 27


Here is the script below
Language="VBSCRIPT"

Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Item("PartBody")

Dim shapes1 As Shapes
Set shapes1 = body1.Shapes

Dim shaft1 As Shape
Set shaft1 = shapes1.Item("Shaft.1")

Dim limit1 As CATBaseDispatch
Set limit1 = shaft1.GetItem("Limit.1")

Dim angle1 As Length
Set angle1 = limit1.Dimension

angle1.Value = 200.000000

part1.Update

End Sub

please look into the issue,Any help is appreciated.Thanks
 
Replies continue below

Recommended for you

Hi Arun

Is it because you are not giving any input to macro like Sketch/Surface for profile and Axis for rotation of Shaft.
You have recorded the macro but need to provide the input.

This is my opinion and hope that it answers your question.
I have created a MACRO with sketch - Rectangular Profile and Vertical direction line of the sketch as rotation axis.
Hope this is full to you.

Language="VBSCRIPT"

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set hybridBodies1 = part1.HybridBodies

'----->with below line the Sketch will always be created in GS1.
'Set hybridBody1 = hybridBodies1.Item("Open_body.1")

'---->>> with below line sketch will always be created in acitve GS
Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

MsgBox ("This Macro is to create sketch for Shaft creation")

Msgbox("Pickup the reference plane for sketch")
Dim InputObjectType(0), Status1
Set selection1 = partDocument1.Selection
selection1.Clear
InputObjectType(0)="Plane"
Status1=selection1.SelectElement2(InputObjectType,"Select plane",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub
Set reference1 = selection1.Item(1).Reference
MsgBox reference1.Name

Msgbox("Pickup the reference point to sketch reference")
InputObjectType(0)="Point"
Status1=selection1.SelectElement2(InputObjectType,"Reference point",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub
Set reference2 = selection1.Item(1).Reference
MsgBox reference2.Name



Set sketches1 = hybridBody1.HybridSketches
Set originElements1 = part1.OriginElements

Set sketch1 = sketches1.Add(reference1)

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(15.000000, 40.000000)

point2D1.ReportName = 3

Set point2D2 = factory2D1.CreatePoint(65.000000, 40.000000)

point2D2.ReportName = 4

Set line2D3 = factory2D1.CreateLine(15.000000, 40.000000, 65.000000, 40.000000)

line2D3.ReportName = 5

line2D3.StartPoint = point2D1

line2D3.EndPoint = point2D2

Set point2D3 = factory2D1.CreatePoint(65.000000, 15.000000)

point2D3.ReportName = 6

Set line2D4 = factory2D1.CreateLine(65.000000, 40.000000, 65.000000, 15.000000)

line2D4.ReportName = 7

line2D4.EndPoint = point2D2

line2D4.StartPoint = point2D3

Set point2D4 = factory2D1.CreatePoint(15.000000, 15.000000)

point2D4.ReportName = 8

Set line2D5 = factory2D1.CreateLine(65.000000, 15.000000, 15.000000, 15.000000)

line2D5.ReportName = 9

line2D5.StartPoint = point2D3

line2D5.EndPoint = point2D4

Set line2D6 = factory2D1.CreateLine(15.000000, 15.000000, 15.000000, 40.000000)

line2D6.ReportName = 10

line2D6.EndPoint = point2D4

line2D6.StartPoint = point2D1

Set constraints1 = sketch1.Constraints

Set reference1 = part1.CreateReferenceFromObject(line2D3)

Set reference2 = part1.CreateReferenceFromObject(line2D1)

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

constraint1.Mode = catCstModeDrivingDimension

Set reference3 = part1.CreateReferenceFromObject(line2D5)

Set reference4 = part1.CreateReferenceFromObject(line2D1)

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

constraint2.Mode = catCstModeDrivingDimension

Set reference5 = part1.CreateReferenceFromObject(line2D4)

Set reference6 = part1.CreateReferenceFromObject(line2D2)

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

constraint3.Mode = catCstModeDrivingDimension

Set reference7 = part1.CreateReferenceFromObject(line2D6)

Set reference8 = part1.CreateReferenceFromObject(line2D2)

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

constraint4.Mode = catCstModeDrivingDimension

Set reference9 = part1.CreateReferenceFromObject(line2D1)

Set reference10 = part1.CreateReferenceFromObject(line2D5)

Set constraint5 = constraints1.AddBiEltCst(catCstTypeDistance, reference9, reference10)

constraint5.Mode = catCstModeDrivingDimension

Set length1 = constraint5.Dimension

length1.Value = 15.000000

Set reference11 = part1.CreateReferenceFromObject(line2D2)

Set reference12 = part1.CreateReferenceFromObject(line2D6)

Set constraint6 = constraints1.AddBiEltCst(catCstTypeDistance, reference11, reference12)

constraint6.Mode = catCstModeDrivingDimension

Set length2 = constraint6.Dimension

length2.Value = 15.000000

Set reference13 = part1.CreateReferenceFromObject(line2D4)

Set constraint7 = constraints1.AddMonoEltCst(catCstTypeLength, reference13)

constraint7.Mode = catCstModeDrivingDimension

Set length3 = constraint7.Dimension

length3.Value = 25.000000

Set reference14 = part1.CreateReferenceFromObject(line2D6)

Set reference15 = part1.CreateReferenceFromObject(line2D4)

Set constraint8 = constraints1.AddBiEltCst(catCstTypeDistance, reference14, reference15)

constraint8.Mode = catCstModeDrivingDimension

Set length4 = constraint8.Dimension

length4.Value = 50.000000

sketch1.CloseEdition

part1.InWorkObject = hybridBody1

part1.UpdateObject sketch1

part1.Update


' - - This roation is done only for reference - need not be used
Set hybridShapeFactory1 = part1.HybridShapeFactory

Set hybridShapeRotate1 = hybridShapeFactory1.AddNewEmptyRotate()

Set reference15 = part1.CreateReferenceFromObject(sketch1)

hybridShapeRotate1.ElemToRotate = reference15

hybridShapeRotate1.VolumeResult = False

hybridShapeRotate1.RotationType = 0

Set reference16 = axis2D1.GetItem("HDirection")

hybridShapeRotate1.Axis = reference16

hybridShapeRotate1.AngleValue = 90.000000

hybridBody1.AppendHybridShape hybridShapeRotate1

part1.InWorkObject = hybridShapeRotate1

part1.Update


Shaft = Msgbox("Do you want to create PAD" , vbYesNo+vbQuestion, "Tell me")

If Shaft = vbYes Then

'Msgbox "Shaft"


Set bodies1 = part1.Bodies
Set body1 = bodies1.Add()
part1.InWorkObject = body1
Set shapeFactory1 = part1.ShapeFactory
Set reference1 = part1.CreateReferenceFromName("")
Set shaft1 = shapeFactory1.AddNewShaftFromRef(reference1)
Set angle1 = shaft1.FirstAngle
angle1.Value = 360.000000
Set parameters1 = part1.Parameters
Set reference2 = part1.CreateReferenceFromObject(sketch1)
shaft1.SetProfileElement reference2
Set geometricElements1 = sketch1.GeometricElements
Set axis2D1 = geometricElements1.Item("AbsoluteAxis")
Set reference3 = axis2D1.GetItem("VDirection")
shaft1.RevoluteAxis = reference3

part1.UpdateObject shaft1

part1.UpdateObject body1

Else

MsgBox " Thank you for using this macro"
End if

part1.Update

End Sub
 
Please check this macro if you want.
In this start and angle is given as input.

Let me know your feedback.

Language="VBSCRIPT"

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set hybridBodies1 = part1.HybridBodies

'----->with below line the Sketch will always be created in GS1.
'Set hybridBody1 = hybridBodies1.Item("Open_body.1")

'---->>> with below line sketch will always be created in acitve GS
Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

MsgBox ("This Macro is to create sketch for Shaft creation")

Msgbox("Pickup the reference plane for sketch")
Dim InputObjectType(0), Status1
Set selection1 = partDocument1.Selection
selection1.Clear
InputObjectType(0)="Plane"
Status1=selection1.SelectElement2(InputObjectType,"Select plane",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub
Set reference1 = selection1.Item(1).Reference
MsgBox reference1.Name

Msgbox("Pickup the reference point to sketch reference")
InputObjectType(0)="Point"
Status1=selection1.SelectElement2(InputObjectType,"Reference point",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub
Set reference2 = selection1.Item(1).Reference
MsgBox reference2.Name



Set sketches1 = hybridBody1.HybridSketches
Set originElements1 = part1.OriginElements

Set sketch1 = sketches1.Add(reference1)

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(15.000000, 40.000000)

point2D1.ReportName = 3

Set point2D2 = factory2D1.CreatePoint(65.000000, 40.000000)

point2D2.ReportName = 4

Set line2D3 = factory2D1.CreateLine(15.000000, 40.000000, 65.000000, 40.000000)

line2D3.ReportName = 5

line2D3.StartPoint = point2D1

line2D3.EndPoint = point2D2

Set point2D3 = factory2D1.CreatePoint(65.000000, 15.000000)

point2D3.ReportName = 6

Set line2D4 = factory2D1.CreateLine(65.000000, 40.000000, 65.000000, 15.000000)

line2D4.ReportName = 7

line2D4.EndPoint = point2D2

line2D4.StartPoint = point2D3

Set point2D4 = factory2D1.CreatePoint(15.000000, 15.000000)

point2D4.ReportName = 8

Set line2D5 = factory2D1.CreateLine(65.000000, 15.000000, 15.000000, 15.000000)

line2D5.ReportName = 9

line2D5.StartPoint = point2D3

line2D5.EndPoint = point2D4

Set line2D6 = factory2D1.CreateLine(15.000000, 15.000000, 15.000000, 40.000000)

line2D6.ReportName = 10

line2D6.EndPoint = point2D4

line2D6.StartPoint = point2D1

Set constraints1 = sketch1.Constraints

Set reference1 = part1.CreateReferenceFromObject(line2D3)

Set reference2 = part1.CreateReferenceFromObject(line2D1)

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

constraint1.Mode = catCstModeDrivingDimension

Set reference3 = part1.CreateReferenceFromObject(line2D5)

Set reference4 = part1.CreateReferenceFromObject(line2D1)

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

constraint2.Mode = catCstModeDrivingDimension

Set reference5 = part1.CreateReferenceFromObject(line2D4)

Set reference6 = part1.CreateReferenceFromObject(line2D2)

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

constraint3.Mode = catCstModeDrivingDimension

Set reference7 = part1.CreateReferenceFromObject(line2D6)

Set reference8 = part1.CreateReferenceFromObject(line2D2)

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

constraint4.Mode = catCstModeDrivingDimension

Set reference9 = part1.CreateReferenceFromObject(line2D1)

Set reference10 = part1.CreateReferenceFromObject(line2D5)

Set constraint5 = constraints1.AddBiEltCst(catCstTypeDistance, reference9, reference10)

constraint5.Mode = catCstModeDrivingDimension

Set length1 = constraint5.Dimension

length1.Value = 15.000000

Set reference11 = part1.CreateReferenceFromObject(line2D2)

Set reference12 = part1.CreateReferenceFromObject(line2D6)

Set constraint6 = constraints1.AddBiEltCst(catCstTypeDistance, reference11, reference12)

constraint6.Mode = catCstModeDrivingDimension

Set length2 = constraint6.Dimension

length2.Value = 15.000000

Set reference13 = part1.CreateReferenceFromObject(line2D4)

Set constraint7 = constraints1.AddMonoEltCst(catCstTypeLength, reference13)

constraint7.Mode = catCstModeDrivingDimension

Set length3 = constraint7.Dimension

length3.Value = 25.000000

Set reference14 = part1.CreateReferenceFromObject(line2D6)

Set reference15 = part1.CreateReferenceFromObject(line2D4)

Set constraint8 = constraints1.AddBiEltCst(catCstTypeDistance, reference14, reference15)

constraint8.Mode = catCstModeDrivingDimension

Set length4 = constraint8.Dimension

length4.Value = 50.000000

sketch1.CloseEdition

part1.InWorkObject = hybridBody1

part1.UpdateObject sketch1

part1.Update


Shaft = Msgbox("Do you want to create PAD" , vbYesNo+vbQuestion, "Tell me")

If Shaft = vbYes Then

'Msgbox "Shaft"

StartAngle=Inputbox("Enter the Start angle")
EndAngle=Inputbox("Enter the End angle")

Set bodies1 = part1.Bodies
Set body1 = bodies1.Add()
part1.InWorkObject = body1
Set shapeFactory1 = part1.ShapeFactory
Set reference1 = part1.CreateReferenceFromName("")
Set shaft1 = shapeFactory1.AddNewShaftFromRef(reference1)
Set angle1 = shaft1.FirstAngle
'angle1.Value = 360.000000
angle1.Value = StartAngle

Set angle2 = shaft1.SecondAngle

angle2.Value = EndAngle

Set parameters1 = part1.Parameters
Set reference2 = part1.CreateReferenceFromObject(sketch1)
shaft1.SetProfileElement reference2
Set geometricElements1 = sketch1.GeometricElements
Set axis2D1 = geometricElements1.Item("AbsoluteAxis")
Set reference3 = axis2D1.GetItem("VDirection")
shaft1.RevoluteAxis = reference3

part1.UpdateObject shaft1

part1.UpdateObject body1

Else

MsgBox " Thank you for using this macro"
End if

part1.Update

End Sub





 
Hi GRNKumar,
I appreciate your help.yes this is what exactly what I was looking for.Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top