2 Replies Latest reply on Sep 4, 2013 12:20 PM by Hersh Sridhar Iyer

    Issue with querying CenterofMass for body

    Hersh Sridhar Iyer

      Hi,

       

       

      I am trying to rotate a body by 180D on the Z axis using InsertMoveCopyBody2().

      The rotation is fine but the center of rotation is different from the value I get by querying using GetMassProperties than the values I get from doing through the UI. The sample part file is attached.

       

       

      Center Of Mass as per UI = 27.735, -0.0005, 21.5419

      Center of mass using API = 21.334, -0.0005, -29.2937

       

       

      The density of the material is obtained using GetUserPreferenceDoubleValue((int)swUserPreferenceDoubleValue_e.swMaterialPropertyDensity). I cross checked this with the body density calculation (mass/volume) and both values are the same.

       

       

      The values I mentioned above are for the body named Boss-Extrude1[1] in the attached part. A sample of the rotation I am trying to achieve through API is also present as a feature (Body-Move/Copy1) in the attached file.

       

      Please advise.

       

      Thanks,

      Hersh

       

      Sample Code

       

      bool status = swModel.Extension.SelectByID2("Boss-Extrude1[1]", "SOLIDBODY", 0, 0, 0, false, 1, null, 0);

                    if (status)

                    {

                                  double[] bodyMassProperties = body.GetMassProperties(m_iSwApp.GetUserPreferenceDoubleValue((int)swUserPreferenceDoubleValue_e.swMaterialPropertyDensity));               

                                  IFeature feature = swModel.FeatureManager.InsertMoveCopyBody2(0, 0, 0, 0, bodyMassProperties[0], bodyMassProperties[1], bodyMassProperties[2], 3.1415926535898, 0, 0, false, 1);

                                  swModel.ClearSelection2(true);

                    }


        • Re: Issue with querying CenterofMass for body
          Simon Turner

          Hi

          I used Body2.GetMassProperties with your part and obtained:

          X = 27.7586, Y = -0.0005, Z = 21.542

           

          I can't see anywhere in your code where you set body. Presumably you use SelectionManager.GetSelectedObject6?

           

          Note that the density won't change the center of mass, so you may as well just use 1.0

           

          Regards

            • Re: Issue with querying CenterofMass for body
              Hersh Sridhar Iyer

              Hi Simon,

               

              I was iterating through the bodies in the part using the following code :

               

              object[] arrBody = (object[])part.GetBodies2((int)swBodyType_e.swSolidBody, false);

                              if (arrBody.Length > 0)

                              {

                                  foreach (Body2 body in arrBody)

              {

              bool status = swModel.Extension.SelectByID2(body.Name, "SOLIDBODY", 0, 0, 0, false, 1, null, 0);

               

              }

                                       .....

                             }

               

              I now know why I was seeing a difference between the center of Mass for Body1. When I iterate through the list, the bodies are not in the same order as what is shown in the UI. For instance, in this case, the first body in the array was Body384.

              It works now. No change was required.

               

              Thanks,

              Hersh