I’ve shown a lot of simple and generic macros on my other CATIA macro articles so I thought I would show a much more complicated and real world use for creating a macro in CATIA V5.
I wrote this script in my spare time while helping a friend out. You see, he had this awesome idea about a new type of roller coaster, a concept he patented and called “the cantilevered coaster.” This new thrill ride has a vehicle cantilevered on the end of a truss connected to two chassis which utilize two sets of rails. OK, it’s not easy to describe so below is an early video concept. This animation was created in CATIA’s DMU Kinematics workbench. The point of the ride is to create an unpredictable and unique ride experience.
Anyway. my friend told me no one had really been successful in creating a working 3D model of this concept and I responded I was up to the challenge. Modeling a roller coaster in CATIA is quite a challenging task, especially one with two sets of rails on top of the vehicle that no one had ever built before. I turned to macros to help in the automatic creation of the track geometry. Today, I am going to share one of the scripts with you.
A typical steel roller coaster track has two tubular rails joined together by other steel members. These members are called cross-ties and they hold the two rails at the correct distance apart. To make my model as simple as possible I chose to go with a rectangular cross-sectional area for the cross-ties. My macro allows you to set the dimensions for the rectangle and at what distance the center of each cross-tie should be offset from one another. This way, I could instantly create hundreds of cross-ties along the thousands of feet of track. The rails were created in CATIA using the rib function.
Here is the general procedure and thought process I mapped out which I used when writing the CATScript. It often helps to have a plan or logic chart while creating a complicated macro.
1. Place point1 on guidecurve1 and point2 on guidecurve2 each at equal distance from their start points.
2. Create plane normal to guidecurve1 through point1.
3. Find an intersection between normal plane and guidecurve2
4. Use near operation to select element from intersection that lie on guidecurve2 (in case if there are multiple intersections). Use point2 as reference element. Then redefine point2 to point found.
5. Place a tangent line to guidecurve1 at point1 using AddNewLineTangency method with length limits -1.5” and 1.5” (tangentline1)
6. Place a tangent line to guidecurve2 at point2 using AddNewLineTangency method with length limits -1.5” and 1.5” (tangentline2)
7. Look for points at ends of tangentline1 with AddNewPointOnCurveFromPercent method using 0% and 100% values.
8. Look for points at ends of tangentline2 with AddNewPointOnCurveFromPercent method using 0% and 100% values.
9. Connect points from 3 and 4 with lines using AddNewLinePtPt method.
10. Create new fill object using AddNewFill method and add tangent lines and lines from 5 to it using it’s AddBound method.
11. Create a pad using AddNewPad method of ShapeFactory object of root part of active document.
A few setup items before running the macro: The rails have to be in their own separate part file. There has to be a geometrical set named “Rollercoaster.” You have to select the guide curves for each rail before running the CATScript.
‘this script automatically adds cross-ties to a roller coaster’s track
‘setup desired input parameters before running script
Private Const ONE_FOOT_MM = 30 ‘ define number of millimetres in one foot
Private Const STEP_LENGTH = 48 ‘ length between cross-ties, in feet
Private Const PAD_SIDE = 3 ‘ length of single cross-tie side, in feet
‘ access the part object
Dim RootPart As Part
Set RootPart = CATIA.ActiveDocument.Part
‘ retrieve target geometrical set named “Rollercoaster”
Dim TargetGeoSet As HybridBody
Set TargetGeoSet = RootPart.HybridBodies.Item(“Rollercoaster”)
‘ define partbody as in work object
Dim PartBody As Body
Set PartBody = RootPart.MainBody
RootPart.InWorkObject = PartBody
‘ access selection object for current document
Dim objSelection As Selection
Set objSelection = CATIA.ActiveDocument.Selection
‘ retrieve reference for first rail curve
Dim GuideCurve1 As AnyObject
Set GuideCurve1 = objSelection.Item2(1).Value
Dim refCurve1 As Reference
If (TypeName(GuideCurve1) = “CATIAReference”) Or (TypeName(GuideCurve1) = “MonoDimFeatEdge”) Then
Set refCurve1 = GuideCurve1
Set refCurve1 = RootPart.CreateReferenceFromObject(GuideCurve1)
‘ Update part to see added objects
This is just one example about how to use CATIA macros in the real world. To get access to the complete CATScript macro code you’ll have to join my CATIA Scripting email newsletter.