New body CATIA macro tutorial + free code

New body CATIA macro tutorial

This post is about basic CATIA programming knowledge.

CATIA macro productivity,new part catia macro


In this tutorials section, I will post simple macros, so you can learn some basic stuff. In this first post, I will talk about basic stuff, like how to record a macro and make some changes. The best way to learn how to make macro is to record one. Also, you can record more than one and then join them into one complex. To record macro go to Tools/Macros/Start recording and after that select CATScript and Start recording.

An important rule is when u recording macro to not make unnecessary clicks. So let’s make a macro for inserting a new body. I will insert a new body and this action will be saved so we can stop recording after that. You will get this cod.

Variable declaration

This new body CATIA macro code is very simple so you need to understand it first. Sub CATMain() is the main function, it always goes on the first place of the code, in the end you have End Sub for end of that main function. Inside this function, you have the code for making a new body. Dim is used for the declaration of variables. You need to declare a variable before you use it. After declaration, you need to set value for the variable.

 In my case, partDocument1 is declared as Document, but it can be named differently. You can give names like TestDocument, Test or whatever you want to set. The value of variable partDocument1 is CATIA.ActiveDocument means that this variable is an active document. It can be any active document like part, product, etc.

In the same way, we define part1, first, we declare it as Part and then we set value for the part. Part1 is CATIA.ActiveDocument and at the same time CATIA Part. Here you can see that kind of active document is very important. You will get an error If you try to run this macro in the product. In the end, we declared the body as part1.bodies. Also, u can write just one declaration like bodies1=CATIA.ActiveDocument.Part.Bodies

Editing macro

 In the end when we understand this recorded new body CATIA macro code we can change if for a bit. For example, we can add the name of the body and for the loop to create more bodies.

Add-on for VB code is making error it converts “&” to “&”

We made just simple changes, we use simple for loop and name property for the body. In this case, we can’t control this for loop, to do that we must use InputBox.

So nothing is changed, we still get 10 bodies, we must say our Loop to go to that input number. In the end, I will make one more change. We will also input the name of the body and use it for increment bodies’ names.

Final code

Add-on for VB code is making error it converts “&” to “&”

 This is our final new body CATIA macro, you can just copy-paste this code. If you have any questions feel free to contact me.

Check my YouTube channel for more cool videos CATIA Tutorials  or section on this site for free macros.

Leave a Reply

Your email address will not be published. Required fields are marked *