Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

How to get center of gravity of bodies

Hi,

 

How can we get the center of gravity of sheet and solid body using NX Journaling(vb)? could you please any one can help me in this regard.

 

Thanks

3 REPLIES

Re: How to get center of gravity of bodies

[ Edited ]

Here's how you do it using the Snap.Compute.MassProperties function. This example is copied from the SNAP Reference Guide. It's a lot more than you need because it computes all mass properties, not just the centroid.

 

Imports Snap, Snap.Create, Snap.Compute, Snap.InfoWindow

Public Class MyProgram

   Public Shared Sub Main()

      Dim a As Double =  40
      Dim b As Double =  80
      Dim c As Double = 120

      ' Create a tetrahedron
      Dim box = Block({0, 0, 0}, a, b, c).Body
      Dim n = Vector.Unit({1/a, 1/b, 1/c})
      Dim trimmer = DatumPlane({a, 0, 0}, n)
      Dim tet = TrimBody(box, trimmer, False).Body

      ' Choose density = 1/volume, to give mass = 1
      tet.Density = 1.0 / 64000

      ' Compute mass properties
      Dim props As MassPropertiesResult = MassProperties(tet)

      'Write out some mass properties
      WriteLine("The surface area is  " & props.Area)
      WriteLine("The mass is          " & props.Mass)
      WriteLine("The volume is        " & props.Volume)
      WriteLine("The density is       " & props.Density)
      WriteLine("The centroid is at   " & props.Centroid.ToString())

      WriteLine("The principal moments and axes are")
      For i As Integer = 0 to 2
         Dim momentString = props.PrincipalMoments(i).ToString("F3")
         Dim   axisString = props.PrincipalAxes(i).ToString("F6")
         WriteLine("  Moment: " & momentString & "  ;  Axis: " & axisString)
      Next

      WriteLine("The inertia tensor is ")
      Dim M As Double(,) = props.InertiaTensor
      Dim r0 As New Vector(M(0,0), M(0,1), M(0,2))  :  WriteLine(r0.ToString("F4"))
      Dim r1 As New Vector(M(1,0), M(1,1), M(1,2))  :  WriteLine(r1.ToString("F4"))
      Dim r2 As New Vector(M(2,0), M(2,1), M(2,2))  :  WriteLine(r2.ToString("F4"))
   End Sub

End Class

' Results: The output in the NX Information window is ...
'      The surface area is  14400
'      The mass is          1
'      The volume is        64000
'      The density is       1.5625E-05
'      The centroid is at   ( 10 , 20 , 30 )
'      The principal moments and axes are
'        Moment: 803.948  ;  Axis: ( -0.939482 , -0.290818 , -0.181104 )
'        Moment: 621.784  ;  Axis: ( 0.332248 , -0.902348 , -0.274553 )
'        Moment: 254.268  ;  Axis: ( 0.083574 , 0.318110 , -0.944363 )
'      The inertia tensor is 
'      ( 780.0000 , 40.0000 , 60.0000 )
'      ( 40.0000 , 600.0000 , 120.0000 )
'      ( 60.0000 , 120.0000 , 300.0000 )

 

 

 

 

To do it using NX/Open alone, use the NXOpen.UF.Modl.AskMassProps3d function.

It returns an array of 46 numbers. The ones with indices 3,4,5 (counting from zero) are the coordinates of the centroid. But beware -- the coordinates are relative to the WCS (unlike almost everything else in NX/Open).

 

山田
yamada

Re: How to get center of gravity of bodies

Thanks for your kind reply...

 

I am new to Snap. How the Snap differ from Journal?

Solution
Solution
Accepted by topic author Ponnambalam
‎08-26-2015 04:32 AM

Re: How to get center of gravity of bodies

> I am new to Snap. How the Snap differ from Journal?
 
This is a bit like asking how a cake is different from sugar.
 
NX/Open and SNAP are libraries of functions that your program can call.
 
A "journal" is a program that you made (primarily) by recording actions in interactive NX, and which you can replay in the NX Journal Editor. A journal (or any other VB program) can call either NX/Open functions, or SNAP functions, or a mixture of the two.
 
If you want to learn more about SNAP, try reading the "Getting Started with SNAP" guide.
 
 
山田
yamada