So basicly i want to know if i have selected a CATPart or a CATProduct in an assembly, but i couldn’t find a suitable check to differentiate between an empty product like “Product4__” and “Part1_ASD2_”. Thats because either one, if selected, will result in Products.Count = 0 and TypeName()=”Product”
Selcetion of “Product1__”, “Part1” “Product3__” result in correct differentiations to CATPart or CATProduct
Catia Assembly Tree Structure
I tried to search a way get the child of the selection but only managed to get the child of a Product. But when a product does not have a child i am at the same problem as before, where “Product4__” and “Part1_ASD2_” behave the same.
Maybe someone can help me here? I am pretty new to CATIA macros, so a question i have for better understanding the Structure is how “Part1” is referenced in “Part1_ASD_”? Maybe that can help me resolve this.
Otherwise is there a difference between an empty product like “Product4__” and a part like “Part1_ASD2_” which i can use?
the code in charge of a crime:
`Sub CatiaCheckSelectionType()
msgBox("Startet")
Set oSelection = CATIA.ActiveDocument.Selection
if oSelection.Count = 1 Then
msgBox(TypeName(oSelection.Item(1).Value))
if TypeName(oSelection.Item(1).Value) = "Product" Then
msgBox("Maybe a Product")
Set CATProduct = oSelection.Item(1).Value
If CATProduct.Products.Count > 0 Then
Set CATProductChild = CATProduct.Products.Item(1)
If TypeName(CATProductChild) = "Product" Then
msgBox ("Definetly a Product")
ElseIf TypeName(CATProductChild) = "Part" Then
msgBox ("Part")
Else
msgBox ("something else in here"))
EndIf
Else
msgBox("Empty Produkt")
EndIf
ElseIf TypeName(oSelection.Item(1).Value) = "Part" then
Set CATPart = oSelection.Item(1).Value
msgBox("En Part it is")
End if
Else
msgBox("Pls Select a Part or a Product")
EndIf
End Sub`
user25130146 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.