This CATIA CATScript will search your open CATIA document for any piece of geometry you specify by name. This CATScript is perfect for scenarios like these:
Sometimes you may have a massive model with tons of geometry and you simply want to edit a certain plane. You know the exact name of the plane is “Plane.72” but you don’t remember where it is located within your specification tree and digging through every single geometrical set would simply take too much time. What do you do?
Creating a simple CATScript is an easy and quick way to get the job done. In this CATIA macro exercise you will learn to:
-
search a CATIA document
-
create an input box
-
create a message box
-
create a For…Next loop
-
use the CATIA.Start Command
Listed below are the basic steps to follow. For a challenge, try to write this code from scratch without looking at my final macro. If you’ve never written a macro from scratch before, check out my guide on how to get started writing CATIA macros.
-
Declare the activedocument as the selection
-
Create a variable of type string
-
Create an input box with the result being saved in the newly create string variable
-
Search the selection by name, which is the string variable entered by the user in the input box
-
Count the number of items found by the search and display the result in a message box
-
Use the Start Command to “center graph” on the geometry found in the search result
To see the complete code and compare it to what you’ve come up with, download the CATIA CATScript from the free downloads page. If you are unable to get the CATScript to work, read my article on what to do when you get stuck. Once completed you may proceed to the next exercise, how to hide geometry.
Dear Emmerett,
thank you for sharing this exercise. I have a question about this script. It is working fine after running, except in the case when I am searching the name which contains characters “-” and “+”. Script returns value of zero in that case. For example if I am searching for part which name is “Platte 10x300x300” the result is some number, but if I am searching name “Platte 10-300-300” the result is zero.
Can you tell me if it is possible to overcome this problem or I mustn`t use charachters “-” and “+” in name.
Regards,
Marko!