0

i have one specific problem that this piece of code does not work as expected:

Private Sub productRename()
    Dim oProd As Product
    Set oProd = CATIA.Documents.Add("Product").Product

    Set oProd = oProd.Products.AddNewComponent("Product", "")
    oProd.Name = "prod.1"

    Set oProd = oProd.Products.AddNewComponent("Product", "")
    oProd.Name = "prod.2"
End Sub

I am trying to change instance name on different levels, works on first level, but not for other levels. particular script creates new product, add sub product, renames it, and then adds another sub level and tries to rename it, but without any error, script will finish without changing last instance. Instance names are not in conflict, unique, as there are only those newly created products.

problem appears on R24 sp4, so please can someone confirm that it works on different sp level?

tsolina
  • 141
  • 15

2 Answers2

2

Use the reference product instead of the instance product to add the new child and you should be able to set the instance name

Dim PN As String 
PN = "12345"
Dim instanceName as String 
instanceName = "12345.X"

Set oProd3 = oProd2.ReferenceProduct.Products.AddNewComponent("Product", PN)
oProd3.Name = instanceName
C R Johnson
  • 964
  • 1
  • 5
  • 12
0

Your code have same behavior also in r25.

I would try something like this:

Sub CATMain()

Dim oProd As Product
Set oProd = CATIA.Documents.Add("Product").Product

Set oProd1 = oProd.Products.AddNewComponent("Product", "prod.1")
'~ oProd1.Name = "prod.1"

Set oProd2= oProd1.Products.AddNewComponent("Product", "prod.2")
'~ oProd2.Name = "prod.2"

    Set oProd3 = oProd2.Products.AddNewComponent("Product", "prod.3")
'~ oProd3.Name = "prod.3"

End Sub
ferdo
  • 178
  • 4
  • thanks ferdo, but i would do this as well, and this would work for catparts, but not for .cgr, if there are instances on different levels, as well, once product is created its name cant be changed, strange – tsolina Nov 23 '16 at 16:55
  • Maybe I didn't understood what you want to do, but from your code and your explanation it seems that you want to add new products one under each other and rename them from the very beginning. What do you want in fact? To create a whole new product structure with all kind of CATIA files ? – ferdo Nov 23 '16 at 17:03
  • exactly, this was just proof of bug in Catia, but i think it was even working on R19... so yes, i am building product from scratch based some folder structure with any kind of data in it, which works well except i cant change names after they are created – tsolina Nov 23 '16 at 17:18