0

I'm working on a project in CATIA and I'm having trouble renaming the instance name using inputs from a userform. I get one of two errors when I run this code, either the file is read-only or improper use of the property.

I'm running into an instance collision when I change the properties of an individual selected product and then create another product after the fact. The problem is that the first instance will take the PartNumber of the second instance the first time the macro is ran unless the instance name is changed. What would be a way to tackle this problem?Two identical instances in the same product

Private Sub Assembly_Field_Update(oCurrentProduct As product)

    Dim oCurrentTreeNode As product
    Dim i As Integer

    ' Loop through every tree node for the current product
    For i = 1 To oCurrentProduct.Products.Count
        Set oCurrentTreeNode = oCurrentProduct.Products.Item(i)

        If oCurrentTreeNode.Products.Count > 0 Then
            Assembly_Field_Update oCurrentTreeNode

        End If

   Next

        If oCurrentTreeNode.Name = CATIA.ActiveDocument.Selection.Item(1).Value.Name Then
            On Error GoTo UserInputs
                oCurrentTreeNode.ReferenceProduct.UserRefProperties.Item(1).Value = DESIGNER_INPUT.Text
                oCurrentTreeNode.ReferenceProduct.UserRefProperties.Item(2).Value = BASE_NUMBER_INPUT
                oCurrentTreeNode.ReferenceProduct.UserRefProperties.Item(3).Value = DASH_NUMBER_INPUT
                oCurrentTreeNode.Name = BASE_NUMBER_INPUT & DASH_NUMBER_INPUT
aaron
  • 81
  • 1
  • 10

2 Answers2

2

The instance name is managed by the owning Product of your Product Instance object.

oCurrentTreeNode.Parent.Item(oCurrentTreeNode.Name).Name = BASE_NUMBER_INPUT & DASH_NUMBER_INPUT

The Parent of an instance product is the Products collection of the owning Product.

The Parent of the ReferenceProduct is the .CATProduct document object.

Things might work slightly different if you try to rename "Component" products in your assembly.

C R Johnson
  • 964
  • 1
  • 5
  • 12
  • Thank you, this will redo the second level. I'll play around with it and see if I can get it to do subsequent levels. – aaron May 04 '20 at 13:33
0

Found the answer for component level instances.

https://www.eng-tips.com/viewthread.cfm?qid=404685

aaron
  • 81
  • 1
  • 10