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
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.