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.
Almost every serious project have 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 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 a 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.
All explained options on the link from before are here. First we need to figure out how to take string from string. So we can use that extract option (String -> Extract(integer, integer): String). This is 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.
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 result of this code is: 01.201.00
Now we need to take name from this part name string.
Extracting part name
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)
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(“_”)
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.
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 product.
If you have any issues feel free to contact me.