How to add a GSD cylinder to a set of points with a CATScript Macro

Here’s a real world example for you. Let’s say you’ve got two parts being fastened together (by bolts, welds, whatever). Your job, Mr. Engineer, is to check to make sure we have enough clearance around each fastening point to be able to get our tools or machines in there in order to able to weld or tighten the parts together. To do this, you may want to create a cylinder at each point and proceed to check to see if there are any intrusions inside of this cylinder. If you have hundreds of connecting point this could become a very time consuming task. That’s where macros come in handy. We can write code which will automatically create specified cylinder geometry at every fastening point.

To add a cylinder in GSD all we need is a point and an axis (or direction). In previous examples (either here or in the newsletter) I’ve shown how to select and loop through a set of points and lines. My fastening center points and axis are saved in two arrays, called aPoints and aLines respectively.

Minus the error handling, here’s the start of my CATScript code:

To figure out what values to enter where to adjust the size of the cylinder, search for “AddNewCylinder” in the CATIA Object Browser.

This is one of those examples where it can be helpful to use the record a macro function. Record yourself creating one cylinder with the dimensions you want then go back and look at the code. The main difference will be the recorded macro will only work for the one point you manually selected. To fully automate the process you will need to add a function like the “For Loop” in order to loop or scroll through all the fastening points within the CATIA part file. Below is the full CATScript for the recorded macro. Notice the difference and simplifications which can be made:

Go from the CATIA Geometry Creation Macro article back to the CATIA tutorial page.

Return to read more CATIA Macro Articles.