×
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

Catia Macro: How to Get Part/Product Document interface from Assembly Selection

Catia Macro: How to Get Part/Product Document interface from Assembly Selection

Catia Macro: How to Get Part/Product Document interface from Assembly Selection

(OP)
Hello Friends,

I have an assembly consisting of many Parts/Products. I want to get Part/Product Document Interface/Object of selected item from specification tree so that I can access its various properties like FullName, Path etc.

Please help

RE: Catia Macro: How to Get Part/Product Document interface from Assembly Selection

Hello Jagandeep,
Try the following GetSelectedProductDocument helper function

CODE --> VBA

Function GetSelectedProductDocument() As Document
    Dim oSelection As Selection
    
    Set oSelection = CATIA.ActiveDocument.Selection
    If oSelection.Count > 0 Then
        If TypeName(oSelection.Item(1).Value) = "Product" Then
            Set GetSelectedProductDocument = oSelection.Item(1).Value.ReferenceProduct.Parent
         End If
    End If
End Function 
and test it with the following

CODE --> VBA

Sub TestOfGetSelectedProductDocument()
    Dim SelectedDocument As Document
    
    Set SelectedDocument = GetSelectedProductDocument
    If Not (SelectedDocument Is Nothing) Then
        MsgBox "Selected Document: " & SelectedDocument.FullName
    End If
End Sub 

-GEL
Imposible is nothing.

RE: Catia Macro: How to Get Part/Product Document interface from Assembly Selection

(OP)
Thanks Dear

RE: Catia Macro: How to Get Part/Product Document interface from Assembly Selection

You are always welcome.

-GEL
Imposible is nothing.

RE: Catia Macro: How to Get Part/Product Document interface from Assembly Selection

I am curious that if I have a product in my screen,how can I get only part names and interface names?Is it possible?Or is there anyway without working my product on screen?

RE: Catia Macro: How to Get Part/Product Document interface from Assembly Selection

(OP)
Please clarify your problem.

RE: Catia Macro: How to Get Part/Product Document interface from Assembly Selection

As I said I have a product and I am looking for a part in this product by macro.I wrote some code sure I did thanks to forum.My target is same names "partname of product with taken partname of Inputbox".Returns messagebox your part name is found.Is that clear?

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
partName = InputBox("Please Enter the Filename")
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))

Dim returnName(current_prod.Products.Count) As String
returnName(i) = current_prod.Products.Item(i)

If partName = returnName(i)
MsgBox partName
End if
Next i
Else
'MsgBox current_prod.ReferenceProduct.Parent.Name

End If

End Sub

RE: Catia Macro: How to Get Part/Product Document interface from Assembly Selection

Summarizely my product has 3 part one of them is "abc.Catpart" named and then if I write inputbox abc returns me by msgbox "Your part is " abc I am new by this way may be I thought I want to explain again,thank you

RE: Catia Macro: How to Get Part/Product Document interface from Assembly Selection

I guess it can be succesful but a bitely some trouble.How can I put into an array my production tree part names or Interfaces names?this is fixxed codes.

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)
Dim partName As String

partName = InputBox("Please Enter the Filename")

If current_prod.Products.Count > 0 Then
For i = 1 To current_prod.Products.Count
Call ListingNames(current_prod.Products.Item(i))
'MsgBox current_prod.Products.Item(i).Name
Next i
Else
If partName = current_prod.ReferenceProduct.Parent.Name Then
MsgBox "succesful"
Else
MsgBox "try again"
End If
MsgBox current_prod.ReferenceProduct.Parent.Name
End If
End Sub

RE: Catia Macro: How to Get Part/Product Document interface from Assembly Selection

(OP)
the post is password protected. how to get it? is it paid?

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