Extract part number and name CATIA macro

Extract part number and name CATIA macro

“Be the change that you wish to see in the world” – MG

Extract part number and name CATIA macro free download.

bald22 (1)
free catia macro

Introduction

Almost every serious project has a lot of parts inside. Hence you must order those parts and have some sort of stock-list. So two basic parameters are part number and part name. There are a lot of different ideas about how to do this specific task. In this post, we want to show you one interesting one. Also in this post, you will learn how to work with strings. For example how to take and extract string, how to split string etc. Therefore with this and CATIA macro knowledge, we will write code for extract part number and name CATIA macro. 

Understanding string operations

Extracting part number

First of all our major goal in this process is how to work with strings. Even more, you can read a little bit on this topic http://catiadoc.free.fr/online/cfyugkwr_C2/cfyugkwrhlpString.htm. At the end of this page, you can download the part with examples inside.

string options in catia

All explained options on the link from before are here. First, we need to figure out how to take a string from a string. So we can use that extract option (String -> Extract(integer, integer): String). This is a classic split string option because first, you need string and then interval. Like in many other programming languages it starts from 0, not from 1. 

01_200_00__EXAMPLE1___________________000000000000 (example part name).

We will extract two first numbers.

string operations catia

So we want to replace that “_” with “.”. `01_201_00__EXAMPLE1___________________000000000000\Part Number` ->Extract(0,2) + “.” . Now we just need to continue with extraction of other numbers and replacement. 

You will get this at the end: `01_201_00__EXAMPLE1___________________000000000000\Part Number` ->Extract(0,2) + “.” +`01_201_00__EXAMPLE1___________________000000000000\Part Number` ->Extract(3,3)+ “.” +`01_201_00__EXAMPLE1___________________000000000000\Part Number` ->Extract(7,2) . 

And the result of this code is: 01.201.00

Now we need to take the name from this part name string. 

Extracting part name

string example

In our case, first 11 places in the part name are for part number, after that 25 places are for part name. So we need to extract from 11 to 25. So extraction will start from 11th place of the string and go 25 strings forward.  

`01_201_00__EXAMPLE1___________________000000000000\Part Number` ->Extract(11,25)

Resault: EXAMPLE1_________________

We need to remove those underlines, so we will search for “_” in this result string.

`01_201_00__EXAMPLE1___________________000000000000\Part Number` ->Extract(11,25) .Search(“_”)

Resault:8

In this case result is integer, and it gives number of letters not the number of “_”. But we can use this number for interval. There is a problem in this approach when you have something like “EXAMPLE_1____”. It will take only “EXAMPLE” not “EXAMPLE_1”. Consequently it is problem when you have those kind of names. 

So let’s use that number and split this string again. 

string operation catia

Result: EXAMPLE1

We combined it all in one relation. You can always make three steps, but you will need two additional parameters then. 

Now we can write our macro code with this information. 

Writing the macro

This code will work only in one part, but you can see how to write it. 

You can also download this extracting part number and name CATIA macro and use it in the product.

If you have any issues feel free to contact me.

2 thoughts on “Extract part number and name CATIA macro

  • May 14, 2020 at 6:29 am
    Permalink

    hello
    I’m NC PGM engineer
    I’m Using CATIA V5R26 control, i saw your macro, and i just want you to build or suggest for me a macro that can automatically numbering the operations in machining file, ex: i have 5 operations, that belong to 1 Subject
    #1: Face/ RGH
    #1.1: FACE/ RGH
    #1.2:
    #2: GRV/ RGH
    ….
    The form is like above example, i mean after finish program, i just want to numbering all operations.

    Reply
    • May 14, 2020 at 6:37 pm
      Permalink

      Hello, can you send me some machining file as example, I m not familier with those files. I ll sent you mail

      Reply

Leave a Reply

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