×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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 --> CATScript

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 

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

(OP)
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 --> CATScript

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 

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

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










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

(OP)
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).

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

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

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

(OP)
> 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. :)

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

(OP)
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 --> VBA

' 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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources