How to use ComputePhysicalProperties () and GetPhysicalProperties() in c#?

Hi,

I am using c# for development.

When I called ComputePhysicalProperties() API to compute mass of part document, it get crashed. In try catch, description of exception is something like"type mismatch..."

Can anybody share example for above API in c#?

 

Thanks in advance.

 

-Amit

 

Posted by: Amit Wadekar
Post date: 5/10/2012 12:23:23 PM

3 REPLIES

Re: How to use ComputePhysicalProperties () and GetPhysicalProperties() in c#?

// assume I already have a model from, say, PartDocument.Models collection

string WritePhysicalProperties(ref SolidEdgePart.Model m)
{
  // input output args
  double density = 1;
  double accuracy = 0.05;
  // output args
  double volume = 0;
  double area = 0;
  double mass = 0;
  var center_of_gravity = Array.CreateInstance(typeof(double), 3);
  var center_of_volume = Array.CreateInstance(typeof(double), 3);
  var global_moments =  Array.CreateInstance(typeof(double), 6); // 
  var principal_moments = Array.CreateInstance(typeof(double), 3); // Ixx Iyy Izz
  var principal_axes = Array.CreateInstance(typeof(double), 9); // 3 axes times 3 coords
  var gyration_radii = Array.CreateInstance(typeof(double), 9); // 3 axes times 3 coords
  double relative_accuracy_achieved = 0;
  int status = 0;

  // note in (val), out, & ref calling conventions
  // void ComputePhysicalProperties(double Density, double Accuracy, out double Volume, out double Area, 
  //      out double Mass, ref Array CenterOfGravity, ref Array CenterOfVolume, ref Array GlobalMomentsOfInteria, 
  //             ref Array PrincipalMomentsOfInteria, ref Array PrincipalAxes, ref Array RadiiOfGyration, out double RelativeAccuracyAchieved, out int Status);
  m.ComputePhysicalProperties(density, accuracy, out volume, out area, out mass, 
                              ref center_of_gravity, ref center_of_volume, ref global_moments, ref principal_moments,
                              ref principal_axes, ref gyration_radii, out relative_accuracy_achieved, out status);

  string result = String.Format("Model {3}: Mass: {0}, Volume {1}, Area {2}", mass, volume, area, m.Name); // etc.
  return result;
}

// result is "Model Design Model: Mass: 9.51050738069406E-06, Volume 9.51050738069406E-06, Area 0.00330933439658918"

 

Posted by: Jay Carlton
Post date: 5/11/2012 9:22:36 AM

Re: How to use ComputePhysicalProperties () and GetPhysicalProperties() in c#?

someone was faster ...

 

Posted by: Wolfgang Kunert
Post date: 5/11/2012 9:24:45 AM

Re: How to use ComputePhysicalProperties () and GetPhysicalProperties() in c#?

Thanks Jay Carlton. Smiley Happy

 

Posted by: Amit Wadekar
Post date: 5/14/2012 2:28:29 AM