Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Macro To Retrieve Inertia Matrix For Multiple Part Bodies In CATIA V5 R21 1

Status
Not open for further replies.

evereux

Aerospace
Feb 17, 2013
14
FR
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!

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
 
Replies continue below

Recommended for you

After much blood, sweat and tears I got it figured out. I hope this proves useful to other people.

The code isn't particular clean or easy to follow at the moment sorry.

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 TheInertiasList As Inertias
            Set TheInertiasList = objSPAWkb.Inertias

            Dim NewInertia As Inertia
            Set NewInertia = TheInertiasList.Add(body1)

                       Dim Matrix (8)
            NewInertia.GetInertiaMatrix Matrix

            Dim bodyArea As Interger
            bodyArea = objMeasurable.Area
            bodyArea =  bodyArea * 1550
            bodyArea2 = bodyArea /2

            Dim objCOG (2)
            objMeasurable.GetCOG objCOG

            ' 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) =  (Matrix(0) * 3417.171898209)
            Excel.cells(RwNum+1,11) =  (Matrix(4) * 3417.171898209)
            Excel.cells(RwNum+1,12) =  (Matrix(8) * 3417.171898209)

            RwNum = RwNum+1

Next 'i

End Sub
 
Hello Every body,

I made use of the the above macro

Thanks for sharing

i would wish to retrieve the material used density and mass,for CatiaProduct,CATPart that contains multiple part bodies.
I tried its not happening

Could you please help me

The macro i am looking for to know the properties of the full assembly and i am using it for weight reduction

i have attached the sample output i am looking for

Thanks in advance










 
 http://files.engineering.com/getfile.aspx?folder=110a9624-8078-4ade-b204-d3e138e5d758&file=Output_File.jpg
Yes, the macro above is only designed to work with a single catpart that has multiple part bodies. I'm trying now to create macro that iterates through an assembly. I'll post the result when I have that (hopefully this weekend). But, it won't process all the part bodies within the part. You'll have to incorporate the above into my new script to do so (unless I have time to do that too).

 
Hi,

Thanks for your time

I tried modifing the above macro to retrive the volume, area, material, density and mass of single CatPart with multiple bodies.I was sucessfull only with volume not with material, density and mass.

If you can help me in getting the material, density and mass for single CatPart with multiple bodies (ie.. for the above Macro)

I will rum the macro individually for CatPart of assembly and compute the weight of full Assy manually

Please help me

Happy weekend in advance
 
> If you can help me in getting the material, density and mass for single CatPart with multiple bodies (ie.. for the above Macro)

Try reading the V5automation.chm file that comes with CATIA. Cross reference that with what I've done above and should be able to work it out. I've done all the hard stuff. :)
 
Clean up some of my noob mistakes* so that it'll work within a VBA project.

I've also added some basic formatting.

* Objects not dimmed
* Bad ordering
* Spelling mistakes

Code:
' written by evereux
Option Explicit
Sub CATMain()

On Error Resume Next
Dim Excel As Object
Set Excel = GetObject(, "EXCEL.Application")

'Before launching excel, make sure it's closed.


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

Dim partDoc As Object
Set partDoc = CATIA.ActiveDocument.Part
Dim docname As String
docname = partDoc.name

Dim objSPAWkb
Set objSPAWkb = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")


Excel.Visible = True



' Dump data into spreadsheet

'Format the columns
Excel.Range("A:A").ColumnWidth = 5
Excel.Range("B:B").ColumnWidth = 30
Excel.Range("C:L").ColumnWidth = 15
Excel.Range("A:L").Font.name = "Arial"
Excel.Range("A:L").Font.Size = 10

'Format the cells of the top row
Excel.Range("1:1").Font.Bold = True
Excel.Range("1:1").RowHeight = 20
Excel.Range("1:1").Font.Size = 11
    
'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
Dim bodyNumber As Integer
bodyNumber = partDoc.Bodies.Count

Dim RwNum As Integer
RwNum = 1


For i = 1 To bodyNumber

            Dim body1 As Body
            Set body1 = partDoc.Bodies.Item(i)
            
            Dim namebody As String
            namebody = body1.name
            
            Dim objRef As Object
            Dim objMeasurable
            
            Set objRef = partDoc.CreateReferenceFromObject(body1)
            Set objMeasurable = objSPAWkb.GetMeasurable(objRef)

            Dim TheInertiasList As Inertias
            Set TheInertiasList = objSPAWkb.Inertias

            Dim NewInertia
            Set NewInertia = TheInertiasList.Add(body1)

            Dim Matrix(8)
            NewInertia.GetInertiaMatrix Matrix

            Dim bodyArea
            bodyArea = objMeasurable.Area
            
            bodyArea = bodyArea * 1550
            
            Dim bodyArea2 As Integer
            bodyArea2 = bodyArea / 2

            Dim objCOG(2)
            objMeasurable.GetCOG objCOG

            ' 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) = (Matrix(0) * 3417.171898209)
            Excel.cells(RwNum + 1, 11) = (Matrix(4) * 3417.171898209)
            Excel.cells(RwNum + 1, 12) = (Matrix(8) * 3417.171898209)

            RwNum = RwNum + 1

Next 'i
 
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top