Hi to all.
I'm trying to modify a Catia macro (CAASpoInertia.CATScript located in the CAAScdDmuUseCases module) to export Excel instead to a Msgbox. Thus far, I cannot make it run. I keep getting a Compile error (User-defined type not defined).
Can someone please help me?
Thank you.
Here is the code I'm using,
Option Explicit
Sub CATMain()
' Retrieve the selected component
Dim oSelection As Selection
Set oSelection = CATIA.ActiveDocument.Selection
Dim oProduct As AnyObject
On Error Resume Next
Set oProduct = oSelection.FindObject("CATIAProduct")
If (Err.Number <> 0) Then
MsgBox "No selected product"
Else
On Error GoTo 0
' Compute the inertia
Dim oInertia As AnyObject
Set oInertia = oProduct.GetTechnologicalObject("Inertia")
' Read the inertia data
Dim dMass As Double
dMass = oInertia.Mass
Dim dCoordinates(2)
oInertia.GetCOGPosition dCoordinates
' Display the results
'MsgBox oProduct.Name & ": Mass = " & CStr(dMass) & ", Center of gravity : X = " & _
'CStr(dCoordinates(0)) & ", Y = " + CStr(dCoordinates(1)) & ", Z = " + CStr(dCoordinates(2))
Dim Excel As Object
Dim workbooks As workbooks
Dim workbook As Excel.workbook
Dim worksheet As Excel.worksheet
Set Excel = CreateObject("Excel.Application")
Excel.Visible = True
Set workbooks = Excel.Application.workbooks
Set myworkbook = Excel.workbooks.Add
Set objsheet1 = Excel.Sheets.Add
objsheet1.Cells(1, 1) = oProduct.Name
objsheet1.Cells(1, 2) = CStr(dMass)
End If
End Sub
I'm trying to modify a Catia macro (CAASpoInertia.CATScript located in the CAAScdDmuUseCases module) to export Excel instead to a Msgbox. Thus far, I cannot make it run. I keep getting a Compile error (User-defined type not defined).
Can someone please help me?
Thank you.
Here is the code I'm using,
Option Explicit
Sub CATMain()
' Retrieve the selected component
Dim oSelection As Selection
Set oSelection = CATIA.ActiveDocument.Selection
Dim oProduct As AnyObject
On Error Resume Next
Set oProduct = oSelection.FindObject("CATIAProduct")
If (Err.Number <> 0) Then
MsgBox "No selected product"
Else
On Error GoTo 0
' Compute the inertia
Dim oInertia As AnyObject
Set oInertia = oProduct.GetTechnologicalObject("Inertia")
' Read the inertia data
Dim dMass As Double
dMass = oInertia.Mass
Dim dCoordinates(2)
oInertia.GetCOGPosition dCoordinates
' Display the results
'MsgBox oProduct.Name & ": Mass = " & CStr(dMass) & ", Center of gravity : X = " & _
'CStr(dCoordinates(0)) & ", Y = " + CStr(dCoordinates(1)) & ", Z = " + CStr(dCoordinates(2))
Dim Excel As Object
Dim workbooks As workbooks
Dim workbook As Excel.workbook
Dim worksheet As Excel.worksheet
Set Excel = CreateObject("Excel.Application")
Excel.Visible = True
Set workbooks = Excel.Application.workbooks
Set myworkbook = Excel.workbooks.Add
Set objsheet1 = Excel.Sheets.Add
objsheet1.Cells(1, 1) = oProduct.Name
objsheet1.Cells(1, 2) = CStr(dMass)
End If
End Sub