×
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 to collect an array part name

How to collect an array part name

How to collect an array part name

(OP)
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

RE: How to collect an array part name

This might help you

CODE --> VBA

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 

RE: How to collect an array part name

(OP)
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

RE: How to collect an array part name

(OP)

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

RE: How to collect an array part name

CODE --> VBA

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 

RE: How to collect an array part name

(OP)
Thank you jagandeep really!You know I am a student and I was thinking to give up because of hopeless.You gave dare me.

RE: How to collect an array part name

(OP)
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

RE: How to collect an array part name

Welcome Dear

RE: How to collect an array part name

(OP)
Thank you dear jagandeep.

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