CATIA VBA: Instance rename -multi level
CATIA VBA: Instance rename -multi level
(OP)
Hello, I am new catia vba user and I have tried to find a solution to my problem on this forum and elsewhere but to no avail. I am sure it's a simple problem but it has me stumped.
I have written a code using VBA to rename the instance names and part numbers in a catia product. It does this for all the products within the top level product and all the parts within the individual products. The code works fine except for renaming the instance names in level 2 of the product tree. Eg.:
works perfectly. But
doesn't do anything at all.
It's weird because i can change the part number in the level 2 easily using
Any guidance will be appreciated.
Thanks.
I have written a code using VBA to rename the instance names and part numbers in a catia product. It does this for all the products within the top level product and all the parts within the individual products. The code works fine except for renaming the instance names in level 2 of the product tree. Eg.:
CODE --> VBA
oprods.item(1).name = "Top level instance"
CODE --> VBA
oprods.item(1).products.item(1).name = "2nd level instance"
It's weird because i can change the part number in the level 2 easily using
CODE --> VBA
oprods.item(1).products.item(1).partnumber = "2nd level part number"
Any guidance will be appreciated.
Thanks.





RE: CATIA VBA: Instance rename -multi level
Take a look at my macro here:
http://www.eng-tips.com/viewthread.cfm?qid=365400
Drew Mumaw
www.textsketcher.com
www.drewmumaw.com
RE: CATIA VBA: Instance rename -multi level
Thanks for this. It works but I don't understand why my method doesn't. Would you be kind enough to shed light on this? I am genuinely curious.
Let's say i don't want loops, and i only want to change a specific instance name of a specific part within a product. Why doesn't the below work?
CODE --> vba
Thanks again.
RE: CATIA VBA: Instance rename -multi level
please give info like CATProduct, CATPart or Component
indocti discant et ament meminisse periti
RE: CATIA VBA: Instance rename -multi level
CODE --> VBA
oprods.item(1) is the first product in the CATIA tree. oprods.item(1).products.item(1) is the first part within the product.
I can change the part number of the part using oprods.item(1).products.item(1).partnumber = "Some part number" but I can't change the instance name using the same logic (using .name instead of .partnumber). It doesn't give any error. It just doesn't do it and skips it.
RE: CATIA VBA: Instance rename -multi level
CODE --> VBA
Sub CATMain() Set CATIA = GetObject(, "CATIA.application") 'Msg.Show GetNextNode CATIA.ActiveDocument.Product 'Unload Msg End Sub Sub GetNextNode(oCurrentProd As Product) 'On Error Resume Next Set oProdDoc = CATIA.ActiveDocument oCurrentProd.ApplyWorkMode DESIGN_MODE Set oProd = oProdDoc.Product Set oProds = oProd.Products Dim oCurrentTreeNode As Product Dim instnosarray(2000) As String For i = 1 To oCurrentProd.Products.Count Set oCurrentTreeNode = oCurrentProd.Products.Item(i) oitem = InStr(1, oCurrentTreeNode.Name, "ITEM", vbBinaryCompare) oitm = InStr(1, oCurrentTreeNode.Name, "ITM", vbBinaryCompare) y = Mid(oCurrentTreeNode.PartNumber, 1, 14) If oitem > 0 Then x = Mid(oCurrentTreeNode.Name, oitem, 8) x2 = Mid(x, 5, 4) ElseIf oitm > 0 Then x = Mid(oCurrentTreeNode.Name, oitm, 7) x2 = Mid(x, 4, 4) Else x = oCurrentTreeNode.Name x2 = x End If instnosarray(i) = x k = 0 For j = 1 To i If instnosarray(j) = x Then k = k + 1 End If Next oCurrentTreeNode.Name = x & "." & k --------------Doesn't do anything oCurrentTreeNode.PartNumber = y & x2 --------------Works fine If oCurrentTreeNode.Products.Count > 0 Then GetNextNode oCurrentTreeNode End If Next End SubRE: CATIA VBA: Instance rename -multi level
Drew Mumaw
www.textsketcher.com
www.drewmumaw.com