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!

How to collect an array part name

Status
Not open for further replies.

suleymanyaman

Industrial
Jul 30, 2013
29
Hi I have some code and also I am new.I want to ask a questıon.The codes in below how can I get part name of product (ıt meanscurrent_prod.ReferenceProduct.Parent.Name) in an array?
Can you help me please?Thank you.

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
 
Replies continue below

Recommended for you

This might help you

Code:
Sub CATMain()

    Dim productdocument1 As ProductDocument
    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
    
    MsgBox productdocument1.Product.Products.Item(1).Name
    MsgBox productdocument1.Product.Products.Item(1).PartNumber
    MsgBox productdocument1.Product.Products.Item(1).ReferenceProduct.Parent.Name

End Sub
 
Sorry but it doesnt work , this method supplied to find coordinate system part.For example my product's first partname is product start part "Product Start CS.CATPart".This method returns "Product Start CS.1 " and so ıt does not work.I wan to say again ,when I enter into what I want to part name in "Inputbox" and if programme find it in subpart it should be returned by MessageBox.As a result I want to put into array whole subPartNames then according to "if statement" I wan to find before inputbox part name.

for example, inputbox-- partName = InputBox("Please Enter the part name")

(I wrote 1234.CATPart)

'In here "current_prod.ReferenceProduct.Parent.Name" is put in array How???

'and then

For i=1 To current_prod.Products.Count
if partName=myArray(i)

MsgBox "This your your part name: " &partName

...

thank you
 

Here you are but myCount gives error unfortuantely.

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


Dim partName As String
partName = InputBox("Please Enter the Filename")
Call ListingNames(productDocument1.Product)


End Sub

Sub ListingNames(current_prod)

Dim myCount As Integer
myCount = 0
Dim myArray(myCount) As String

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
myCount = myCount + 1
Next i
Else
For j = 0 To myArray.Lenght - 1
myArray(j) = current_prod.ReferenceProduct.Parent.Name

If partName = myArray(j) Then
MsgBox "Your part is found: " & partName
Else
'MsgBox "try again"
End If
Next j
MsgBox current_prod.ReferenceProduct.Parent.Name
End If
End Sub

 
Code:
Option Explicit

Dim strSearch As String
Dim PartFound As Boolean
'Dim MySelection As Selection

Sub CATMain()
    
    Dim MyDoc As Document
    Dim MyProduct As Product
    
    Set MyDoc = CATIA.ActiveDocument
    Set MyProduct = MyDoc.Product
    'Set MySelection = MyDoc.Selection
    
    strSearch = InputBox("Input Search String")
    PartFound = False
    
    If strSearch = "" Then
        MsgBox "Search String is Empty", vbExclamation, "Error"
        End
    End If
    
    Call Traverse(MyProduct)
    
    If PartFound = True Then
        MsgBox "Part Found", vbInformation, "Success"
    Else
        MsgBox "Part Not Found", vbExclamation, "Fail"
    End If

End Sub

Sub Traverse(MyProduct As Product)

    Dim i As Integer
    Dim PartName As String
    
    If PartFound = True Then
        Exit Sub
    End If
    
    For i = 1 To MyProduct.Products.Count
    
        If MyProduct.Products.Item(i).Products.Count = 0 Then
        
            PartName = MyProduct.Products.Item(i).ReferenceProduct.Parent.Name
            
            If PartName = strSearch Then
            
                PartFound = True
                
                Dim MySelection As Selection
                Set MySelection = MyProduct.Parent.Selection
                
                MySelection.Clear
                MySelection.Add MyProduct.Products.Item(i)
                
                CATIA.StartCommand "center graph"
                CATIA.StartCommand "reframe on"
                
            End If
            
        Else
        
            Call Traverse(MyProduct.Products.Item(i).ReferenceProduct)
            
        End If
        
    Next
    
End Sub
 
Thank you jagandeep really!You know I am a student and I was thinking to give up because of hopeless.You gave dare me.
 
Maybe you can think about greedy please not,but how can I use this part information to reach position ,translation ,rotation values about interfaces?If you are busy you can give just one sample for example just rotation and I can research other topic.Otherwise I can produce idea logicly about other topic.I hope all is well!
Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor