Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

jagandeep

Automotive
May 27, 2013
82
IN
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
 
Replies continue below

Recommended for you

Hello Jagandeep,
Try the following GetSelectedProductDocument helper function
Code:
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:
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.
 
You are always welcome.

-GEL
Imposible is nothing.
 
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?
 
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
 
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
 
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
 
the post is password protected. how to get it? is it paid?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top