0

I have a Catia V5 Product inside another product : enter image description here

The following code allows me to add a new part called "PART_NAME" inside the main "Product1" (Note that 2 lines are commented) :

    Dim CATIA = GetObject(, "CATIA.Application")
    Dim documents1 = CATIA.Documents
    Dim productDocument1 = CATIA.ActiveDocument

    Dim product1 = productDocument1.Product
    Dim products1 = product1.Products

    'Dim product2 = products1.Item("Product2.1")
    'Dim products2 = product2.Products

    Dim product3 = products1.AddNewComponent("Part", "")
    product3.Name = "PART_NAME"

The result is the following : enter image description here

Now I would like to add this part but inside "Product2.1". I then execute the same code, but uncomment everything and slightly change the last two code lines :

    Dim CATIA = GetObject(, "CATIA.Application")
    Dim documents1 = CATIA.Documents
    Dim productDocument1 = CATIA.ActiveDocument

    Dim product1 = productDocument1.Product
    Dim products1 = product1.Products

    Dim product2 = products1.Item("Product2.1")
    Dim products2 = product2.Products

    Dim product3 = products2.AddNewComponent("Part", "")
    product3.Name = "PART_NAME_2"

The result is the following :

enter image description here

The part is indeed added but not renamed correctly. Why ?

Guigui
  • 21
  • 4
  • I'm using VB.NET – Guigui Dec 18 '22 at 01:29
  • I realized that if I close my assembly, open it again and launch the code to add the part, the instance name will again end by ".1" instead of ".2" or ".3"... Meaning that closing and opening the assembly again "reset" the "counter". But how can I either reset this counter myself to make sure it's always ".1", or modify the instance name to my liking ? – Guigui Dec 18 '22 at 12:14
  • I changed my first post question to make it easier to understand my problem. – Guigui Dec 19 '22 at 11:02
  • You could try to "switch" to the sub-product (and not its instance) using `Dim product2 = products1.Item("Product2.1").ReferenceProduct` and the rename the instance of the part (or even create it) – Shrotter Dec 19 '22 at 12:26

0 Answers0