Hi all,
I am coming to you to solve a problem. I am a really beginner in Macro and I'm trying to make a macro to create springs.
I apologize in advance for the ugly code below (I recorded a macro then modified it in VBSCRIPT).
My macro works like that : I put differents values (diameters, lengh..) then I have to select a point then a line.
I succed with "select the point" (this is the code below) but I fail when I try to add the code "select a line".
When I try to add "select a line", I have a error with this line :"Set hybridShapePlaneNormal1 = hybridShapeFactory1.AddNewPlaneNormal(reference1, reference2)"
To use this macro you need a point and a line in your CATPart and the line need to be renamed by "Droite.2", that why I would like to select a line instead a rename each times lines
Anyone would have an idea how to solve this issue
Thanks a lot
Brice
---------------------------------------------------
Language="VBSCRIPT"
Sub CATMain()
var1 = replace(inputbox("Rayon du ressort" , "MACRO POUR RESSORT","8"), ".",",")
var2 = replace(inputbox("Longueur du ressort", "MACRO POUR RESSORT","30"), ".",",")
var3 = replace(inputbox("Diametre du fil" , "MACRO POUR RESSORT","0,5"), ".",",")
var4 = replace(inputbox("Pas de l'helice" , "MACRO POUR RESSORT","2"), ".",",")
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Add()
part1.Update
Dim hybridShapeFactory1 As Factory
Set hybridShapeFactory1 = part1.HybridShapeFactory
Dim parameters1 As Parameters
Set parameters1 = part1.Parameters
Dim hybridShapeLineExplicit1 As Parameter
Set hybridShapeLineExplicit1 = parameters1.Item("Droite.2")
Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(hybridShapeLineExplicit1)
Dim parameters2 As Parameters
Set parameters2 = part1.Parameters
msgbox "Selectionner un point"
Dim Mysel1 As Object
Set Mysel1 = CATIA.ActiveDocument.Selection
Dim InPutObjectType(0)
InPutObjectType(0) = "AnyObject"
Status = Mysel1.SelectElement2(InPutObjectType, "Select a point", False)
Dim reference2 As Reference
Set reference2 = Mysel1.Item(1).Reference
Dim hybridShapePlaneNormal1 As HybridShapePlaneNormal
Set hybridShapePlaneNormal1 = hybridShapeFactory1.AddNewPlaneNormal(reference1, reference2)
hybridBody1.AppendHybridShape hybridShapePlaneNormal1
part1.InWorkObject = hybridShapePlaneNormal1
part1.Update
Dim reference3 As Reference
Set reference3 = Mysel1.Item(1).Reference
Dim reference4 As Reference
Set reference4 = part1.CreateReferenceFromObject(hybridShapePlaneNormal1)
Dim hybridShapeCircleCtrRad1 As HybridShapeCircleCtrRad
Set hybridShapeCircleCtrRad1 = hybridShapeFactory1.AddNewCircleCtrRad(reference3, reference4, False, var1)
hybridShapeCircleCtrRad1.SetLimitation 1
hybridBody1.AppendHybridShape hybridShapeCircleCtrRad1
part1.InWorkObject = hybridShapeCircleCtrRad1
part1.Update
Dim hybridShapeDirection1 As HybridShapeDirection
Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(1.000000, 2.000000, 3.000000)
Dim reference5 As Reference
Set reference5 = part1.CreateReferenceFromObject(hybridShapeCircleCtrRad1)
Dim hybridShapeExtremum1 As HybridShapeExtremum
Set hybridShapeExtremum1 = hybridShapeFactory1.AddNewExtremum(reference5, hybridShapeDirection1, 1)
hybridBody1.AppendHybridShape hybridShapeExtremum1
part1.InWorkObject = hybridShapeExtremum1
part1.Update
Dim reference6 As Reference
Set reference6 = part1.CreateReferenceFromObject(hybridShapeCircleCtrRad1)
Dim reference7 As Reference
Set reference7 = part1.CreateReferenceFromObject(hybridShapeExtremum1)
Dim hybridShapePointOnCurve1 As HybridShapePointOnCurve
Set hybridShapePointOnCurve1 = hybridShapeFactory1.AddNewPointOnCurveWithReferenceFromPercent(reference6, reference7, 0.000000, False)
hybridBody1.AppendHybridShape hybridShapePointOnCurve1
part1.InWorkObject = hybridShapePointOnCurve1
part1.Update
Dim reference8 As Reference
Set reference8 = part1.CreateReferenceFromObject(hybridShapeLineExplicit1)
Dim reference9 As Reference
Set reference9 = part1.CreateReferenceFromObject(hybridShapePointOnCurve1)
Dim hybridShapeHelix1 As HybridShapeHelix
Set hybridShapeHelix1 = hybridShapeFactory1.AddNewHelix(reference8, False, reference9, var4, 10.000000, False, 0.000000, 0.000000, False)
hybridShapeHelix1.PitchLawType = 0
hybridShapeHelix1.SetStartingAngle 0.000000
hybridShapeHelix1.SetHeight var2
hybridBody1.AppendHybridShape hybridShapeHelix1
part1.InWorkObject = hybridShapeHelix1
part1.Update
Dim reference10 As Reference
Set reference10 = part1.CreateReferenceFromObject(hybridShapeHelix1)
Dim reference11 As Reference
Set reference11 = part1.CreateReferenceFromObject(hybridShapePointOnCurve1)
Dim hybridShapePlaneNormal2 As HybridShapePlaneNormal
Set hybridShapePlaneNormal2 = hybridShapeFactory1.AddNewPlaneNormal(reference10, reference11)
hybridBody1.AppendHybridShape hybridShapePlaneNormal2
part1.InWorkObject = hybridShapePlaneNormal2
part1.Update
Dim reference12 As Reference
Set reference12 = part1.CreateReferenceFromObject(hybridShapePointOnCurve1)
Dim reference13 As Reference
Set reference13 = part1.CreateReferenceFromObject(hybridShapePlaneNormal2)
Dim hybridShapeCircleCtrRad2 As HybridShapeCircleCtrRad
Set hybridShapeCircleCtrRad2 = hybridShapeFactory1.AddNewCircleCtrRad(reference12, reference13, False, var3)
hybridShapeCircleCtrRad2.SetLimitation 1
hybridBody1.AppendHybridShape hybridShapeCircleCtrRad2
part1.InWorkObject = hybridShapeCircleCtrRad2
part1.Update
Dim bodies1 As Bodies
Set bodies1 = part1.Bodies
Dim body1 As Body
Set body1 = bodies1.Add()
part1.Update
Dim shapeFactory1 As Factory
Set shapeFactory1 = part1.ShapeFactory
Dim rib1 As Rib
Set rib1 = shapeFactory1.AddNewRibFromRef(Nothing, Nothing)
Dim reference14 As Reference
Set reference14 = part1.CreateReferenceFromObject(hybridShapeCircleCtrRad2)
rib1.SetProfileElement reference14
Dim reference15 As Reference
Set reference15 = part1.CreateReferenceFromObject(hybridShapeHelix1)
rib1.CenterCurveElement = reference15
part1.Update
End Sub
---------------------------------------------------
I am coming to you to solve a problem. I am a really beginner in Macro and I'm trying to make a macro to create springs.
I apologize in advance for the ugly code below (I recorded a macro then modified it in VBSCRIPT).
My macro works like that : I put differents values (diameters, lengh..) then I have to select a point then a line.
I succed with "select the point" (this is the code below) but I fail when I try to add the code "select a line".
When I try to add "select a line", I have a error with this line :"Set hybridShapePlaneNormal1 = hybridShapeFactory1.AddNewPlaneNormal(reference1, reference2)"
To use this macro you need a point and a line in your CATPart and the line need to be renamed by "Droite.2", that why I would like to select a line instead a rename each times lines
Anyone would have an idea how to solve this issue
Thanks a lot
Brice
---------------------------------------------------
Language="VBSCRIPT"
Sub CATMain()
var1 = replace(inputbox("Rayon du ressort" , "MACRO POUR RESSORT","8"), ".",",")
var2 = replace(inputbox("Longueur du ressort", "MACRO POUR RESSORT","30"), ".",",")
var3 = replace(inputbox("Diametre du fil" , "MACRO POUR RESSORT","0,5"), ".",",")
var4 = replace(inputbox("Pas de l'helice" , "MACRO POUR RESSORT","2"), ".",",")
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Add()
part1.Update
Dim hybridShapeFactory1 As Factory
Set hybridShapeFactory1 = part1.HybridShapeFactory
Dim parameters1 As Parameters
Set parameters1 = part1.Parameters
Dim hybridShapeLineExplicit1 As Parameter
Set hybridShapeLineExplicit1 = parameters1.Item("Droite.2")
Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(hybridShapeLineExplicit1)
Dim parameters2 As Parameters
Set parameters2 = part1.Parameters
msgbox "Selectionner un point"
Dim Mysel1 As Object
Set Mysel1 = CATIA.ActiveDocument.Selection
Dim InPutObjectType(0)
InPutObjectType(0) = "AnyObject"
Status = Mysel1.SelectElement2(InPutObjectType, "Select a point", False)
Dim reference2 As Reference
Set reference2 = Mysel1.Item(1).Reference
Dim hybridShapePlaneNormal1 As HybridShapePlaneNormal
Set hybridShapePlaneNormal1 = hybridShapeFactory1.AddNewPlaneNormal(reference1, reference2)
hybridBody1.AppendHybridShape hybridShapePlaneNormal1
part1.InWorkObject = hybridShapePlaneNormal1
part1.Update
Dim reference3 As Reference
Set reference3 = Mysel1.Item(1).Reference
Dim reference4 As Reference
Set reference4 = part1.CreateReferenceFromObject(hybridShapePlaneNormal1)
Dim hybridShapeCircleCtrRad1 As HybridShapeCircleCtrRad
Set hybridShapeCircleCtrRad1 = hybridShapeFactory1.AddNewCircleCtrRad(reference3, reference4, False, var1)
hybridShapeCircleCtrRad1.SetLimitation 1
hybridBody1.AppendHybridShape hybridShapeCircleCtrRad1
part1.InWorkObject = hybridShapeCircleCtrRad1
part1.Update
Dim hybridShapeDirection1 As HybridShapeDirection
Set hybridShapeDirection1 = hybridShapeFactory1.AddNewDirectionByCoord(1.000000, 2.000000, 3.000000)
Dim reference5 As Reference
Set reference5 = part1.CreateReferenceFromObject(hybridShapeCircleCtrRad1)
Dim hybridShapeExtremum1 As HybridShapeExtremum
Set hybridShapeExtremum1 = hybridShapeFactory1.AddNewExtremum(reference5, hybridShapeDirection1, 1)
hybridBody1.AppendHybridShape hybridShapeExtremum1
part1.InWorkObject = hybridShapeExtremum1
part1.Update
Dim reference6 As Reference
Set reference6 = part1.CreateReferenceFromObject(hybridShapeCircleCtrRad1)
Dim reference7 As Reference
Set reference7 = part1.CreateReferenceFromObject(hybridShapeExtremum1)
Dim hybridShapePointOnCurve1 As HybridShapePointOnCurve
Set hybridShapePointOnCurve1 = hybridShapeFactory1.AddNewPointOnCurveWithReferenceFromPercent(reference6, reference7, 0.000000, False)
hybridBody1.AppendHybridShape hybridShapePointOnCurve1
part1.InWorkObject = hybridShapePointOnCurve1
part1.Update
Dim reference8 As Reference
Set reference8 = part1.CreateReferenceFromObject(hybridShapeLineExplicit1)
Dim reference9 As Reference
Set reference9 = part1.CreateReferenceFromObject(hybridShapePointOnCurve1)
Dim hybridShapeHelix1 As HybridShapeHelix
Set hybridShapeHelix1 = hybridShapeFactory1.AddNewHelix(reference8, False, reference9, var4, 10.000000, False, 0.000000, 0.000000, False)
hybridShapeHelix1.PitchLawType = 0
hybridShapeHelix1.SetStartingAngle 0.000000
hybridShapeHelix1.SetHeight var2
hybridBody1.AppendHybridShape hybridShapeHelix1
part1.InWorkObject = hybridShapeHelix1
part1.Update
Dim reference10 As Reference
Set reference10 = part1.CreateReferenceFromObject(hybridShapeHelix1)
Dim reference11 As Reference
Set reference11 = part1.CreateReferenceFromObject(hybridShapePointOnCurve1)
Dim hybridShapePlaneNormal2 As HybridShapePlaneNormal
Set hybridShapePlaneNormal2 = hybridShapeFactory1.AddNewPlaneNormal(reference10, reference11)
hybridBody1.AppendHybridShape hybridShapePlaneNormal2
part1.InWorkObject = hybridShapePlaneNormal2
part1.Update
Dim reference12 As Reference
Set reference12 = part1.CreateReferenceFromObject(hybridShapePointOnCurve1)
Dim reference13 As Reference
Set reference13 = part1.CreateReferenceFromObject(hybridShapePlaneNormal2)
Dim hybridShapeCircleCtrRad2 As HybridShapeCircleCtrRad
Set hybridShapeCircleCtrRad2 = hybridShapeFactory1.AddNewCircleCtrRad(reference12, reference13, False, var3)
hybridShapeCircleCtrRad2.SetLimitation 1
hybridBody1.AppendHybridShape hybridShapeCircleCtrRad2
part1.InWorkObject = hybridShapeCircleCtrRad2
part1.Update
Dim bodies1 As Bodies
Set bodies1 = part1.Bodies
Dim body1 As Body
Set body1 = bodies1.Add()
part1.Update
Dim shapeFactory1 As Factory
Set shapeFactory1 = part1.ShapeFactory
Dim rib1 As Rib
Set rib1 = shapeFactory1.AddNewRibFromRef(Nothing, Nothing)
Dim reference14 As Reference
Set reference14 = part1.CreateReferenceFromObject(hybridShapeCircleCtrRad2)
rib1.SetProfileElement reference14
Dim reference15 As Reference
Set reference15 = part1.CreateReferenceFromObject(hybridShapeHelix1)
rib1.CenterCurveElement = reference15
part1.Update
End Sub
---------------------------------------------------