How do you get the Document's Instance Number?
How do you get the Document's Instance Number?
(OP)
Hi,
I have the following code below. My intent is to get all the instance partnumbers from all the documents in my activedocument.
I expect that the variable "nam" below will give me XXXXXXX.1 ,XXXXXXX.2, ...,XXXXXX.n
but the variable just returns XXXXXXXX.CATPART, XXXXXXXX.CATPART,....,XXXXXXXX.CATPART with no instance numbering.
I think nam = docus.Item(k).Name is the wrong approach but I do not know any other approach.
Any suggestions/solutions?
'------------
Sub CATMain()
Dim docus As Documents: Set docus = CATIA.Documents
Dim r As Integer
Dim i As Integer: i = docus.Count
For k = 1 To i
Dim nam As String: nam = docus.Item(k).Name
MsgBox nam
Next
End Sub
I have the following code below. My intent is to get all the instance partnumbers from all the documents in my activedocument.
I expect that the variable "nam" below will give me XXXXXXX.1 ,XXXXXXX.2, ...,XXXXXX.n
but the variable just returns XXXXXXXX.CATPART, XXXXXXXX.CATPART,....,XXXXXXXX.CATPART with no instance numbering.
I think nam = docus.Item(k).Name is the wrong approach but I do not know any other approach.
Any suggestions/solutions?
'------------
Sub CATMain()
Dim docus As Documents: Set docus = CATIA.Documents
Dim r As Integer
Dim i As Integer: i = docus.Count
For k = 1 To i
Dim nam As String: nam = docus.Item(k).Name
MsgBox nam
Next
End Sub





RE: How do you get the Document's Instance Number?
There are different approaches for this....the most simple and fastest one is to save your CATProduct as txt.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: How do you get the Document's Instance Number?
That approach works, but if I want to use catvba all the way, is there another way of getting the instance numbers?
Thanks for the quick response
RE: How do you get the Document's Instance Number?
This code is listing all partnumbers and partnames according to their's positions in document's tree
CODE -->
Sub CATMain() Set productDocument1 = CATIA.ActiveDocument If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then MsgBox "Active CATIA Document is not a Product. Open a Product file and run this script again.", , msgboxtext Exit Sub End If Call ListingNames(productDocument1.Product) End Sub Sub ListingNames(current_prod) If current_prod.Products.Count > 0 Then For i = 1 To current_prod.Products.Count Call ListingNames(current_prod.Products.Item(i)) Next Else MsgBox current_prod.Name End If End SubIf You are interested in Macros in Catia (Catscripts, Catvba) feel free to send me a message. I will wrote specified macros for free and post it on eng-tips forum
RE: How do you get the Document's Instance Number?
CODE --> CATScript
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: How do you get the Document's Instance Number?
That works! Although I've gotten a bit greedy and tried if I can acquire the parent product of each selected item the macro loops through. I tried doing this:
Prnt = selection1.item(i).value.parent.name. It worked well for the first item on the selection. But the next iteration gave "products" for Prnt. Does that mean that the loop is also looking at the grandparents of the item (i)?
If this is the case, how do I tell the compiler to just look at the immediate parent of item (i)?
Thanks!
RE: How do you get the Document's Instance Number?
SelectionList = SelectionList & chr(10) & selection1.Item(i).Value.Name & " ; " & selection1.Item(i).Value.Parent.Parent.Name
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: How do you get the Document's Instance Number?
CODE --> VBScript
Dim Listed Sub CATMain() Set productDocument1 = CATIA.ActiveDocument If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then MsgBox "Active CATIA Document is not a Product. Open a Product file and run this script again.", , msgboxtext Exit Sub End If ProductName="" Call ListingNames(productDocument1.Product,ProductName) Msgbox Listed End Sub Sub ListingNames(current_prod,pathname) If current_prod.Products.Count > 0 Then pathname2 = pathname &"\"& current_prod.name For i = 1 To current_prod.Products.Count Call ListingNames(current_prod.Products.Item(i),pathname2) Next Else 'MsgBox pathname &"\" & current_prod.Name Listed = Listed & chr(10) & pathname &"\" & current_prod.Name End If End SubThis one would works at every level of assembly (I Reported my post below, there is small mistake, that I've noticed after submitting)
LukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013
RE: How do you get the Document's Instance Number?
Thanks!
RE: How do you get the Document's Instance Number?
CODE --> CATVBS
and testing macro:
CODE --> CATVBS
Dim Listed Sub CATMain() Set productDocument1 = CATIA.ActiveDocument If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then MsgBox "Active CATIA Document is not a Product. Open a Product file and run this script again.", , msgboxtext Exit Sub End If ProductName="" Call ListingNames(productDocument1.Product,ProductName) Msgbox Listed End Sub Sub ListingNames(current_prod,pathname) If current_prod.Products.Count > 0 Then pathname2 = pathname &"\"& current_prod.name For i = 1 To current_prod.Products.Count Call ListingNames(current_prod.Products.Item(i),pathname2) Next Else 'MsgBox pathname &"\" & current_prod.Name Listed = Listed & chr(10)&"Assembly level:"&AssemblyLevel(current_prod) &" path: " &pathname &"\" & current_prod.Name End If End Sub Function AssemblyLevel(oProduct) If oProduct.Parent.Parent.Name="CNEXT" Then AssemblyLevel=1 Else AssemblyLevel=AssemblyLevel(oProduct.Parent.Parent)+1 End If End FunctionLukaszSz. Poland, Warsaw University of Technology, Faculty of Power and Aeronautical Engineering : MEchanical Engineering. BsC - 2013
RE: How do you get the Document's Instance Number?
But if you are using this script on a CATProduct coming from a PDM system (like VPM for example), you have to modify because is giving an error due to the first condition:
If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
MsgBox "Active CATIA Document is not a Product. Open a Product file and run this script again.", , msgboxtext
Exit Sub
End If
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...