Language="VBSCRIPT"
'*********************************************************
' Purpose:  This macro can be used interactively to compute inertia data from a product in a CATProduct. 
'              
' Inputs :  Product Name
'*********************************************************
Sub CATMain()

   'Acquire the name from the user
   Dim ProductName As String
   ProductName = "Product1" 'Default value
   ProductName = InputBox("Give the name of the product", "Product Name", ProductName )
   If ProductName <> "" Then

      'Find the product in the CATProduct
      Dim Product As AnyObject
      Set Product = CATIA.ActiveDocument.Product.Products.Item(ProductName)

      ' Find the workbench
      Dim TheSPAWorkbench As Workbench
      Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench ( "SPAWorkbench" )

      ' Create the inertia
      Dim ProductInertia As Inertia
      Set ProductInertia = TheSPAWorkbench.Inertias.Add(Product)

      ' Get the inertia data
      Dim Mass As Double
      Mass = ProductInertia.Mass
      Dim Coordinates(2)
      ProductInertia.GetCOGPosition Coordinates
      Dim Matrix(8)
      
      ' Display the results
      MsgBox ProductInertia.Name+_
             ", Mass = "+Cstr(Mass)+_
             ", Center of Gravity   : X   = "+Cstr(Coordinates(0))+", Y   = "+Cstr(Coordinates(1))+", Z   = "+Cstr(Coordinates(2))

   End If

End Sub
