I have a assembly like:
RootProduct:
I'm writing code that check what type of item user selected and add new Part with my own parameters to the selected Product. And I have a problem with checking what user selected. If use code below:
InputType(0) = "Product"
Set ItemSelection = ActDoc.Selection
ItemSelection.Clear
SelStatus = ItemSelection.SelectElement2(InputType, "Choose Product", True)
If SelStatus = "Cancel" Then
Exit Sub
End If
If ItemSelection.Item(1).Type = "Product" Then
' add new Part
ElseIf ItemSelection.Item(1).Type = "Part" Then
MsgBox "It's Part. Script closed."
Exit Sub
End If
But problem is that in CATIA tree "Part" and "Product" have same type - Product.
May be exist another method how to check what type of data user selected? Thank you.
Dim bIsProd as Boolean
Dim oSelectedProd as Product
Set oSelectedProd = ItemSelection.Item(1).Value
bIsProd = typename(oSelectedProd.ReferenceProduct.Parent) = "ProductDocument"
It is slightly more complicated if you are using "Visualization Mode" for your assembly In that case the property ReferenceProduct will fail. However, If your assembly is freshly opened and in "Visualization Mode" you may assume any ReferenceProduct properties that fail are Parts. Products will work.
It also may not work (I can't remember) if your documents are not saved yet.