How to get an instance name and a file path of a child unloaded document in a Product via CATIA API?

Richard Grob

How to get an instance name and a file path of a child unloaded document in a Product via CATIA API?
Hello all,

We try to get the "Link to Reference" properties (the CATIA Part/Product file path) and the Instance name property via CATIA VBA API when this CATIA Part/Product is not loaded in the CATIA (it is a broken link).

Please have a look at the attached file (image.png).

When this child CATIA Part/CATIA Product object is loaded we can easily do it in the following way:
Set cad = catia.ActiveDocument
Set childProds = cad.product.Products
    
Dim childProd As product
Set childProd = childProds.Item(1)
 
Dim instanceName As String
Dim filePath As String
instanceName = childProd.name
filePath = childProd.ReferenceProduct.Parent.fullName

or with the CAIEngine API:

Dim catEngine As StiEngine
Set catEngine = catia.GetItem("CAIEngine")
   
Dim product As ProductDocument
Set product = GetActiveProductDocument()
   
Dim rootItem As StiDBItem
Set rootItem = catEngine.GetStiDBItemFromAnyObject(product)
   
Dim childs As StiDBChildren
Set childs = rootItem.GetChildren
   
Dim curChild As StiDBItem
Set curChild = childs.Item(1)
                       
Dim filePath As String
filePath = curChild.GetDocumentFullPath()
          
Dim obj As Object
Set obj = curChild.GetDocument()
       
Dim refProd As product
Set refProd = obj.product.ReferenceProduct
   
Dim instanceName As String
   
Set cad = catia.ActiveDocument
Set childProds = cad.product.Products
Dim childProd As product
For i = 1 To childProds.count
    Set childProd = childProds.Item(i)
    If (childProd.ReferenceProduct Is refProd) Then
        instanceName = childProd.name
        Exit For
    End If
Next i



But when this child CATIA Part/CATIA Product object is NOT loaded:
  • In the first approach the childProd.ReferenceProduct property doesn't work;
  • In the second appoach the curChild.GetDocument() method doesn't work.


Could you please help us to find a solution?
Attachments

  • image.png (666.6k)
Edited By:
Richard Grob[Subscriber Members] @ Nov 02, 2022 - 07:38 PM (IDLW)
Richard Grob[Subscriber Members] @ Nov 02, 2022 - 07:38 PM (IDLW)
Richard Grob[Subscriber Members] @ Nov 02, 2022 - 07:39 PM (IDLW)
Richard Grob[Subscriber Members] @ Nov 02, 2022 - 07:41 PM (IDLW)

Little Cthulhu

RE: How to get an instance name and a file path of a child unloaded document in a Product via CATIA API?
(in response to Richard Grob)

There's no way to retrieve anything but instance name of unloaded instance with Automation. Even CAA doesn't has a clear approach to that.

CATIA doesn't reference documents by path, it uses unique identifiers called UUID. Anyway to retrieve further info you have to parse .CATProduct file which is ugly but doable.