How know Type "Product" or "Component"

LECLERC Sebastien

How know Type "Product" or "Component"

Hii :)

I have check everywhere and I no Find solution for know difference between "Product" or "Component" for list all Element in a Product Tree. I find this:
http://www.coe.org/p/fo/et/thread=15608

it works, but when a Component is inside other Component, impossible to detect the TYPE, it is all time PRODUCT....

CATIA seem not have a Fonction Class TYPE DOCUMENT..... It is strange....

I would Like Detect all Time the Type exact for list in a Excel : Part, Product or Component.
Emett Ross seem too not have a solution... I have check all its MACRO...


Thx

Edited By:
LECLERC Sebastien[Subscriber Members] @ Nov 14, 2021 - 05:18 PM (IDLW)

Little Cthulhu

RE: How know Type "Product" or "Component"
(in response to LECLERC Sebastien)

Interestingly, I've been looking into this quite recently.

The difference between Product and Component is that that the latter doesn't have it's own document (.CATProduct). We can utilize that and perform a partnumber check:

if prd.ReferenceProduct.Parent.Product.PartNumber <> prd.PartNumber then
' prd is Component
end if

LECLERC Sebastien

RE: How know Type "Product" or "Component"
(in response to Little Cthulhu)

I try :)

But no works with a Component inside a COmponent :

Public Sub check_types_main()

Dim oProductDoc As ProductDocument
Set oProductDoc = CATIA.ActiveDocument

Dim oRootProduct As Product
Set oRootProduct = oProductDoc.Product

Call check_types(oRootProduct)

End Sub


Sub check_types(oProductInWork)

Dim oProducts As Products
Set oProducts = oProductInWork.Products

Dim i As Integer

For i = 1 To oProducts.Count

Dim NameOfProdPart As String
NameOfProdPart = oProducts.Item(i).ReferenceProduct.Parent.Name

If NameOfProdPart Like "*CATPart*" Then
MsgBox "Part! " & NameOfProdPart

ElseIf NameOfProdPart Like "*Product*" Then

If NameOfProdPart = oProductInWork.Name & ".CATProduct" Then
MsgBox "Component! " & NameOfProdPart
Else
MsgBox "Product! " & NameOfProdPart
End If

End If

' Appel récursif
If oProducts.Item(i).Products.Count > 0 Then
Call check_types(oProducts.Item(i).ReferenceProduct)
End If

Next

End Sub


Little Cthulhu

RE: How know Type "Product" or "Component"
(in response to LECLERC Sebastien)

And how is your code related to mine? You haven't used the solution that i've posted.

Are you having troubles in copying it to your macro?

LECLERC Sebastien

RE: How know Type "Product" or "Component"
(in response to Little Cthulhu)

Sorry but when I can put your code in my Code for detect Component inside Component?

Thx.

En réponse à Little Cthulhu :

Et quel est le rapport entre ton code et le mien ? Vous n'avez pas utilisé la solution que j'ai posté.

Avez-vous des problèmes pour le copier dans votre macro ?