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
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
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 SubRE: How to collect an array 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
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 SubRE: How to collect an array part name
RE: How to collect an array part name
Regards
RE: How to collect an array part name
RE: How to collect an array part name