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.
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:
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.
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