Check if product exist
Check if product exist
(OP)
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?
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





RE: Check if product exist
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 SubTiago Figueiredo
Tooling Engineer
Youtube channel:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...