New part CATIA macro tutorial + free code
New Part CATIA macro tutorial
Learn how to make simple but very useful CATIA macros.
First of all, making a new part in every CATIA session is like a must to take action. Certainly using an integrated new part option is not very acceptable. It is due to many reasons. Also defining the name of the part is not practical. Even more, you must save this file to a folder and so on. As a result, I decided to show you how to make a new part CATIA macro in this tutorial.
Recording New Part CATIA macro
The best and easiest way to make the new part CATIA macro is to record one. So after recording you can edit it. Therefore let’s record this macro then. So we got this code.
Certainly, this is a very simple code to understand. If you want to read even more about the declaration of variables you can do it on this link. First of all, a very important line for us in this macro is “Set partDocument1 = documents1.Add(“Part”)”. This line code defines making the new part and part name. Also, let’s record saving this macro in the folder.
Also, we need to record one more macro for changing the name of this part.
This line of code “Set product1 = partDocument1.GetItem(“Part5″)” is very important. We don’t want “Part5”, because it will work only for that part.
Editing New Part CATIA macro
As a result, we have three macro codes. So let’s combine them into one new macro. Consequently, you can see we have some same lines in these three macros. So we can add the last two lines of code from the second macro to the first. In contrast to the third macro, we must make a change. So we must change “Part5” with Partdocument.part.name.
Hence try to run this code now. It will make a new part and save it to the location. In my case location is “C:\Users\Me\Desktop\New folder\Part1.CATPart”.Finally, we want to edit that part name. Due we will use an input box. So we will ask a user to input part name information for this new part CATIA macro.
Certainly very good practice is to previously define name profile like.
Therefore a user needs to copy this profile and just edit it. As a result, you will get very organized part names. Finally, we just need to change two more things and we got a new part CATIA macro.
Final code for New Part CATIA macro
Final usable code for New Part CATIA macro.
You can see also my video tutorial, how to make this macro.
2 thoughts on “New part CATIA macro tutorial + free code”
Please tell me what is the code to get Instance name using part number in a cat product using CATIA VBA.
here are few lines of code that can help you.
Set oSel = CATIA.Activedocument.Selection
strArray(0) = “AnyObject”
Dim sStatus As String
sStatus = oSel.SelectElement3(strArray, “Select Part”, False, CATMultiSelectionMode.CATMultiSelTriggWhenUserValidatesSelection, False)
It depends on what do you want to select and what do you want to get.
Are you want to select that part from the user or?
In that case, code will be diferent.