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!

Check if product exist

Status
Not open for further replies.

iscariot

Mechanical
Oct 15, 2009
154
DE
What would be the best way to check if a product exist in active model?
Would be ok like below, or there are better ways?
Code:
Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = productDocument1.Selection

selection1.Search "(Name=*test* & CATProductSearch.Product),all"

If selection1.Count >= 1 Then
	msgbox "Exist"
End If

End Sub
 
Replies continue below

Recommended for you

That is probably the simplest way.

But for large assemblies it can be really slow.


This can be faster, but you need to have the file name the same as PartNumber
Code:
Sub CATMain()
On Error Resume Next
Dim documents1 As Documents
Set documents1 = CATIA.Documents
Dim productDocument1 As ProductDocument
Dim partDocument1 As PartDocument
Dim product1 As Product
Dim Selection1 As Selection
Set Selection1 = CATIA.ActiveDocument.Selection

Dim Name As String

Name = InputBox("Insert the document name")

If Name = "" Then
Exit Sub
End If

'Find a CATProduct

Set productDocument1 = documents1.Item(Name & ".CATProduct")

Set product1 = productDocument1.Product



'Find a CATPart


Set partDocument1 = documents1.Item(Name & ".CATPart")


Set product1 = partDocument1.GetItem(Name)




If product1.PartNumber = "" Then

MsgBox ("Product not found")
Else

MsgBox ("Found: " & product1.PartNumber)

End If


End Sub





Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top