×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How do you get the Document's Instance Number?

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

RE: How do you get the Document's Instance Number?

(OP)
Hi ferdo,
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?

I've posted similiar code few days ago:

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 Sub 

If 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

Sub CATMain()

REM Works in an active CATProduct

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = productDocument1.Selection

Dim HSOSynchronizedFilter(0)
Dim sel
Dim Status
Set sel = CATIA.ActiveDocument.Selection
HSOSynchronizedFilter(0) = "SetCATIADotHSOSynchronizedToFalse"

selection1.Search "(CATAsmSearch.Part + CATAsmSearch.Product),all"

For i = 1 to selection1.Count 
SelectionList = SelectionList & chr(10) & selection1.Item(i).Value.Name 
Next

MsgBox "Selection is " & SelectionList 

selection1.Clear
HSOSynchronizedFilter(0) = "SetCATIADotHSOSynchronizedToTrue"

End Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

RE: How do you get the Document's Instance Number?

(OP)
Hi ferdo,

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?

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 Sub 

This 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?

(OP)
Yes! it works!!!....using .Parent twice is something very foreign to me. I didn't know that was possible.

Thanks!

RE: How do you get the Document's Instance Number?

I wrote small function:

CODE --> CATVBS

Function AssemblyLevel(oProduct)
If oProduct.Parent.Parent.Name="CNEXT" Then
AssemblyLevel=1
Else
AssemblyLevel=AssemblyLevel(oProduct.Parent.Parent)+1
End If
End Function 

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 Function 

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?

Nice solutions, a star from me.

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...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources