Lego CATIA macro

Lego

Lego CATIA macro

“For me stories are like Lego blocks. If I don’t put one down, I can’t put the next one down.” Om Malik

lego block CATIA macro
Lego catia macro

Introduction

This is a new Lego CATIA macro application for making Lego blocks and inserting them into the product. We have one more post about Lego block maker. But in this post, we have a different approach. In the first post, we make everything with macro, like first, we make the pad, after that pins and so on. Hence in this post, we will not do any modeling, just change a few parameters. All modeling was done in part with rules. So you just need to create some simple rules. Because of that, we have two main controlling parameters, pin, and row number. And these two are connected with the rule. 

if Number_of_row == 2

{Block_W=15.8 }

if Number_of_row ==1

{Block_W=7.8}

A first specific case is when a number of rows are 2 then the block width is 15.8 and when it is 1 then it is 7.8. 

if Number_of_pins ==2

{PartBody\RectPattern.2\Activity =false}

if Number_of_pins >2

{PartBody\RectPattern.2\Activity =true}

In the second example, we want to have a pattern when a number of pins are more than 2. So you can activate or deactivate elements inside the tree.

You can see all of these in the part, we will put a link for download.  

We use this picture to make a model for Lego block.

lego block dimensions

Writing macro code

Steps in this CATIA macro:

1. Make selection of product

2. Make newFrom from the base part

3. Change parameters using inputBox and rules

4. Save part to the location using inputBox

5. Add the part to the product

It’s very important to make these simple steps for every macro. So you can go step by step when one is working you can go to the next and so one. It’s very hard to write full code at once and there can be a lot of errors. 

Conclusion

Maybe you don’t need this Lego CATIA macro, but you can learn a lot from it. 

1. How to make multiple selection and how to use it in code

2. How to make NewFrom 

3. How to change the name of the part and save it to location

4. How to control part parameters from CATScript

5. How to use InputBox(user inputs) to control if statements

6. How to add a part to the product

Using this example you can easily make CATScript for inserting the base part in your model. We think that’s very good practice. 

You can download it for free and use it. 

If you have any issues feel free to contact me.

Leave a Reply

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