0

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)

enter image description here

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.
  • You could use a workaround: export the _ListingReport_ (analyze -> Bill of Materials) as txt. By parsing this output you get the old path of the missing products. Be aware the export (use macro recorder) and the txt file is depending on the language of the GUI. – Shrotter Nov 02 '22 at 08:44
  • Hi, @Shrotter, thank you for the suggestion. I have tried it. Generally it works. But for an unloaded document/product in the result txt document I can see only: "2 Unretrieved document: SMARTEAM://_STFILE_C:\v5work\HZTL217995P0013VAL001.CATPart%VERS_1". I mean, the instance name is missing here. I can get the instance name only when a document/part is loaded. An example from the exported text file: "2 HZTL429711P0011DUM001 Instance Name: HZTL429711P0011DUM001.1 Path name: C:\v5work\HZTL429711P0011DUM001.CATPart". – Александр Терентьев Nov 02 '22 at 14:22
  • Of course, we can parse this result txt file to obtain the document structure for the majority of the loaded child documents. Then recursively go through the cad.product.Products collection and build the second structure only with the instance names. On base on it, we can compare these two structures and get the file paths from the first collection and the instance names from the second collection. But, in my view, it will not be a beauty and fast solution. I belief, that there should be an appropriate way how to do it in the CATIA API without these crutches. – Александр Терентьев Nov 02 '22 at 14:32
  • Of course this wound be a fast and clean solution, its only a workaround. I guess to get the path directly is only possible with CAA. – Shrotter Nov 02 '22 at 15:24

0 Answers0