Hello,
I'm trying to write a C# program to get the mass properties of a selected subassembly in a large assembly. I thought I was following the documentation properly, but I run into one of two problems:
the "AddBodies" function for a mass property object throws an exception if I use the type "swBodyType_e.swSolidBody" as an input.
the mass value returned is that for the entire assembly instead of the added part if I use the type "swBodyType_e.swGeneralBody".
I've attached the function below.
---------
private void APIexample(SldWorks swApp)
{
try
{
ModelDoc2 swModel;
ModelDocExtension swDocExt;
MassProperty swMass;
SelectionMgr swSelMgr;
Component2 swComp;
swModel = (ModelDoc2)swApp.ActiveDoc;
swDocExt = (ModelDocExtension)swModel.Extension;
swMass = (MassProperty)swDocExt.CreateMassProperty();
swSelMgr = (SelectionMgr)swModel.SelectionManager;
swComp = (Component2)swSelMgr.GetSelectedObjectsComponent2(1);
int type = (int)swBodyType_e.swSolidBody;
//This is the line that fails...
swMass.AddBodies(swComp.GetBodies2(type));
MessageBox.Show("Mass: " + swMass.Mass);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
---------
Thanks,
--Tyler
I'm trying to write a C# program to get the mass properties of a selected subassembly in a large assembly. I thought I was following the documentation properly, but I run into one of two problems:
the "AddBodies" function for a mass property object throws an exception if I use the type "swBodyType_e.swSolidBody" as an input.
the mass value returned is that for the entire assembly instead of the added part if I use the type "swBodyType_e.swGeneralBody".
I've attached the function below.
---------
private void APIexample(SldWorks swApp)
{
try
{
ModelDoc2 swModel;
ModelDocExtension swDocExt;
MassProperty swMass;
SelectionMgr swSelMgr;
Component2 swComp;
swModel = (ModelDoc2)swApp.ActiveDoc;
swDocExt = (ModelDocExtension)swModel.Extension;
swMass = (MassProperty)swDocExt.CreateMassProperty();
swSelMgr = (SelectionMgr)swModel.SelectionManager;
swComp = (Component2)swSelMgr.GetSelectedObjectsComponent2(1);
int type = (int)swBodyType_e.swSolidBody;
//This is the line that fails...
swMass.AddBodies(swComp.GetBodies2(type));
MessageBox.Show("Mass: " + swMass.Mass);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
---------
Thanks,
--Tyler