Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error CATIA BOM Export using Macro

Status
Not open for further replies.

pieswt

Mechanical
Nov 16, 2023
9
Hello Friends,
I am trying to export "Bill of Material"(BOM) using Macro for CATProduct. (I recorded the macro and modified it as per my requirement).
The macro is working fine but sometimes I get runtime error as shown below on yellow highlighted line of code.

MicrosoftTeams-image1_n7jj6e.png


When I restart CATIA, the macro start working couple of times and then again same error.
Can someone help me avoid this error and make the macro more robust?

Below is my code:

Code:
Public Sub CATMain()

    Dim Template As String   
    Template = "C:\temp\BOM.xls"
     
    Dim productDocument1 As ProductDocument
    Set productDocument1 = CATIA.ActiveDocument
       
    Dim product1 As Product
    Set product1 = productDocument1.Product

    Dim assemblyConvertor1 As AssemblyConvertor
    Set assemblyConvertor1 = product1.GetItem("BillOfMaterial")

    Dim arrayOfVariantOfBSTR1(4)
    arrayOfVariantOfBSTR1(0) = "Quantity"
    arrayOfVariantOfBSTR1(1) = "Part Number"
    arrayOfVariantOfBSTR1(2) = "Type"
    arrayOfVariantOfBSTR1(3) = "Nomenclature"
    arrayOfVariantOfBSTR1(4) = "Revision"
    Set assemblyConvertor1Variant = assemblyConvertor1
    assemblyConvertor1Variant.SetCurrentFormat arrayOfVariantOfBSTR1

    Dim arrayOfVariantOfBSTR2(1)
    arrayOfVariantOfBSTR2(0) = "Quantity"
    arrayOfVariantOfBSTR2(1) = "Part Number"
    Set assemblyConvertor1Variant = assemblyConvertor1
    assemblyConvertor1Variant.SetSecondaryFormat arrayOfVariantOfBSTR2
   
    [highlight #FCE94F]assemblyConvertor1.[Print] "XLS", Template, product1[/highlight]
  
    MsgBox "Bom Exported Successfully"
    
End Sub
 
Replies continue below

Recommended for you

I'm not sure if this will help, but I noticed it is different from the BOM code I am using.

Instead of
Code:
Dim assemblyConvertor1 As AssemblyConvertor

Try
Code:
Dim assemblyConvertor1 As CATBaseDispatch

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor