Hi,
I have a CATPart that contains multiple part bodies that is open in it's own window. I'd like to iterate through all the part bodies and output bodyname, Area, CofG, Inertia (Ixx, Ixy, Ixz) and mass.
I have the area and CofG working fine but I can't find a solution to retrieving the inertia (I figure the solution will be similar for mass).
I'm aware of the GetTechnologicalObject but that only works for Products (I think) and I can't get the SPAWorkbench to output anything in terms of inertia. The SPAWorkbench is listed as being depcrecated in future versions in the CAA Visual Basic V5 help.
The macro I have so far is below. The code isn't that clean at the moment but I'll post a cleaner working solution as I'm sure it'll be handy for other people.
Any pointers here would be greatly appreciated!
I have a CATPart that contains multiple part bodies that is open in it's own window. I'd like to iterate through all the part bodies and output bodyname, Area, CofG, Inertia (Ixx, Ixy, Ixz) and mass.
I have the area and CofG working fine but I can't find a solution to retrieving the inertia (I figure the solution will be similar for mass).
I'm aware of the GetTechnologicalObject but that only works for Products (I think) and I can't get the SPAWorkbench to output anything in terms of inertia. The SPAWorkbench is listed as being depcrecated in future versions in the CAA Visual Basic V5 help.
The macro I have so far is below. The code isn't that clean at the moment but I'll post a cleaner working solution as I'm sure it'll be handy for other people.
Any pointers here would be greatly appreciated!
Code:
Sub CATMain()
'Before launching excel, make sure it's closed.
On Error Resume Next
Set Excel = GetObject(,"EXCEL.Application")
If Err.Number <> 0 Then
Err.Clear
Set Excel = CreateObject("Excel.Application")
Else
Err.Clear
MsgBox "Please note you have to close Excel", vbCritical
Exit Sub
End If
' Declare all of our objects for excel
Dim Excel As Object
Dim workbooks As workbooks
Dim workbook As workbook
Dim Sheets As Object
Dim Sheet As Object
Dim worksheet As Excel.worksheet
Dim myworkbook As Excel.workbook
Dim myworksheet As Excel.worksheet
Set workbooks = Excel.Applcation.workbooks
Set myworkbook = Excel.workbooks.Add
Set myworksheet = Excel.ActiveWorkbook.Add
Set myworksheet = Excel.Sheets.Add
Dim partDoc As PartDocumet
Set partDoc = CATIA.ActiveDocument.Part
Set objSPAWkb = CATIA.ActiveDocument.GetWorkBench("SPAWorkbench")
Excel.Visible = True
' Dump data into spreadsheet
'Row one
Excel.cells(1,1)="Number"
Excel.cells(1,2)="Part Body Name"
Excel.cells(1,3)="Body Area"
Excel.cells(1,4)="Body Area / 2"
Excel.cells(1,6)="CoG X"
Excel.cells(1,7)="CoG Y"
Excel.cells(1,8)="CoG Z"
Excel.cells(1,10)="Ixx"
Excel.cells(1,11)="Ixy"
Excel.cells(1,12)="Ixz"
Dim i As Integer
bodyNumber = partDoc.Bodies.Count
Dim RwNum As Interger
RwNum = 1
For i = 1 to bodyNumber
Dim body1 As Body
Set body1 = partDoc.Bodies.Item(i)
namebody = body1.name
Set objRef = partDoc.CreateReferenceFromObject(body1)
Set objMeasurable = objSPAWkb.GetMeasurable(objRef)
Dim bodyArea As Interger
bodyArea = objMeasurable.Area
bodyArea = bodyArea * 1550
bodyArea2 = bodyArea /2
Dim objCOG (2)
objMeasurable.GetCOG objCOG
Dim objInertia (8)
objMeasurable.GetInertia objInertia
' Row two
Excel.cells(RwNum+1,1) = i
Excel.cells(RwNum+1,2) = namebody
Excel.cells(RwNum+1,3) = bodyArea
Excel.cells(RwNum+1,4) = bodyArea2
Excel.cells(RwNum+1,6) = (objCOG(0)/25.4)
Excel.cells(RwNum+1,7) = (objCOG(1)/25.4)
Excel.cells(RwNum+1,8) = (objCOG(2)/25.4)
Excel.cells(RwNum+1,10) = objInertia(0)
Excel.cells(RwNum+1,11) = objInertia(1)
Excel.cells(RwNum+1,12) = objInertia(2)
RwNum = RwNum+1
Next 'i
End Sub