×
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

Check if product exist

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?

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

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:
https://www.youtube.com/channel/UC1qdlBeJJEgMgpPLV...

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