Hi
Below is the macro with input AS POINT and reference PLANE as selected by user, it will create a SKETCH inside which there is predefined CIRCLE.
I will create another SKETCH which is having a PREDEFINED SQUARE in side.
My requirement is when this MACRO is run,
I want MACRO ask user for below two options and based on the selection, sketch has to be created.
1. Sketch with Circle
2. Sketch with SQUARE.
How to go forward this using input options.
Please share your thoughts. Thanks in advance
PS: Please share link for MACROS in which INPUT BOX is used for allowing the user to selection options available in macro.
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("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
'-----Created by default macro recording---
'Set sketch1 = sketches1.Item("Sketch.1")
'Set sketch1 = body1.Sketches
'------------------------------
Set originElements1 = part1.OriginElements
Set sketch1 = sketches1.Add(reference1)
'Set sketch1 = originElements1.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(10.000000, 10.000000)
point2D1.ReportName = 3
Set circle2D1 = factory2D1.CreateClosedCircle(10.000000, 10.000000, 4.000000)
circle2D1.CenterPoint = point2D1
circle2D1.ReportName = 4
Set constraints1 = sketch1.Constraints
Set reference1 = part1.CreateReferenceFromObject(circle2D1)
Set constraint1 = constraints1.AddMonoEltCst(catCstTypeRadius, reference1)
constraint1.Mode = catCstModeDrivingDimension
Set length1 = constraint1.Dimension
length1.Value = 4.000000
Set reference2 = part1.CreateReferenceFromObject(line2D1)
Set reference3 = part1.CreateReferenceFromObject(point2D1)
Set constraint2 = constraints1.AddBiEltCst(catCstTypeDistance, reference2, reference3)
constraint2.Mode = catCstModeDrivingDimension
Set length2 = constraint2.Dimension
length2.Value = 10.000000
Set reference4 = part1.CreateReferenceFromObject(line2D2)
Set reference5 = part1.CreateReferenceFromObject(point2D1)
Set constraint3 = constraints1.AddBiEltCst(catCstTypeDistance, reference4, reference5)
constraint3.Mode = catCstModeDrivingDimension
Set length3 = constraint3.Dimension
length3.Value = 10.000000
sketch1.CloseEdition
part1.InWorkObject = hybridBody1
part1.UpdateObject sketch1
part1.Update
End Sub
Below is the macro with input AS POINT and reference PLANE as selected by user, it will create a SKETCH inside which there is predefined CIRCLE.
I will create another SKETCH which is having a PREDEFINED SQUARE in side.
My requirement is when this MACRO is run,
I want MACRO ask user for below two options and based on the selection, sketch has to be created.
1. Sketch with Circle
2. Sketch with SQUARE.
How to go forward this using input options.
Please share your thoughts. Thanks in advance
PS: Please share link for MACROS in which INPUT BOX is used for allowing the user to selection options available in macro.
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("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
'-----Created by default macro recording---
'Set sketch1 = sketches1.Item("Sketch.1")
'Set sketch1 = body1.Sketches
'------------------------------
Set originElements1 = part1.OriginElements
Set sketch1 = sketches1.Add(reference1)
'Set sketch1 = originElements1.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(10.000000, 10.000000)
point2D1.ReportName = 3
Set circle2D1 = factory2D1.CreateClosedCircle(10.000000, 10.000000, 4.000000)
circle2D1.CenterPoint = point2D1
circle2D1.ReportName = 4
Set constraints1 = sketch1.Constraints
Set reference1 = part1.CreateReferenceFromObject(circle2D1)
Set constraint1 = constraints1.AddMonoEltCst(catCstTypeRadius, reference1)
constraint1.Mode = catCstModeDrivingDimension
Set length1 = constraint1.Dimension
length1.Value = 4.000000
Set reference2 = part1.CreateReferenceFromObject(line2D1)
Set reference3 = part1.CreateReferenceFromObject(point2D1)
Set constraint2 = constraints1.AddBiEltCst(catCstTypeDistance, reference2, reference3)
constraint2.Mode = catCstModeDrivingDimension
Set length2 = constraint2.Dimension
length2.Value = 10.000000
Set reference4 = part1.CreateReferenceFromObject(line2D2)
Set reference5 = part1.CreateReferenceFromObject(point2D1)
Set constraint3 = constraints1.AddBiEltCst(catCstTypeDistance, reference4, reference5)
constraint3.Mode = catCstModeDrivingDimension
Set length3 = constraint3.Dimension
length3.Value = 10.000000
sketch1.CloseEdition
part1.InWorkObject = hybridBody1
part1.UpdateObject sketch1
part1.Update
End Sub