New part CATIA macro tutorial + free code

New Part CATIA macro tutorial

Learn how to make simple but very useful CATIA macros.

CATIA macro productivity,new part catia macro

Introduction

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. 

00_00_PART_NAME_________________00-000

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.

If you want to download free Visual Basic new part CATIA macro you can do it on this link.

3 thoughts on “New part CATIA macro tutorial + free code

  • August 12, 2021 at 4:00 pm
    Permalink

    Hi,
    Please tell me what is the code to get Instance name using part number in a cat product using CATIA VBA.

    Thanks,
    Venkat Sai

    Reply
    • August 12, 2021 at 9:09 pm
      Permalink

      Hello,
      here are few lines of code that can help you.

      Sub CATMain()

      Dim oSel
      Set oSel = CATIA.Activedocument.Selection
      Dim strArray(0)
      strArray(0) = “AnyObject”

      Dim sStatus As String
      sStatus = oSel.SelectElement3(strArray, “Select Part”, False, CATMultiSelectionMode.CATMultiSelTriggWhenUserValidatesSelection, False)

      MsgBox oSel.item(1).value.name

      MsgBox oSel.item(1).value.ReferenceProduct.Parent.Part.name

      MsgBox oSel.item(1).value.parent.parent.name
      End Sub

      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.

      Reply
  • January 19, 2024 at 3:57 am
    Permalink

    Hi,
    Please tell me what is the code to get make Custom templates option drafting using CATIA VBA.

    Thanks,
    SURENDHARAN

    Reply

Leave a Reply

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