If I do
Code: Select all
### Begin command Std_SendToPythonConsole
>>> obj = App.getDocument("findMOItest").getObject("Box002")
>>> ### End command Std_SendToPythonConsole
>>> obj.Shape.Mass
6.0
>>> obj.Shape.Volume
6.0
Code: Select all
### Begin command Std_SendToPythonConsole
>>> obj = App.getDocument("findMOItest").getObject("Box002")
>>> ### End command Std_SendToPythonConsole
>>> obj.Shape.Mass
6.0
>>> obj.Shape.Volume
6.0
There is a Part.Solid.Mass property, that seems to be derived from TopoShape, but some search in sources (a quick search) lead to nothing more than refer to a property:OS: Artix Linux (openbox)
Word size of FreeCAD: 64-bit
Version: 0.20.26683 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 0388fbc)
Hash: 0388fbc98d49d874fb341b9037a743bc691d501f
Python version: 3.9.7
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.3
Locale: Italian/Italy (it_IT)
Code: Select all
Py::Float TopoShapePy::getLength(void) const
{
const TopoDS_Shape& shape = getTopoShapePtr()->getShape();
if (shape.IsNull())
throw Py::RuntimeError("shape is invalid");
GProp_GProps props;
BRepGProp::LinearProperties(shape, props);
return Py::Float(props.Mass());
}
Py::Float TopoShapePy::getArea(void) const
{
const TopoDS_Shape& shape = getTopoShapePtr()->getShape();
if (shape.IsNull())
throw Py::RuntimeError("shape is invalid");
GProp_GProps props;
BRepGProp::SurfaceProperties(shape, props);
return Py::Float(props.Mass());
}
Py::Float TopoShapePy::getVolume(void) const
{
const TopoDS_Shape& shape = getTopoShapePtr()->getShape();
if (shape.IsNull())
throw Py::RuntimeError("shape is invalid");
GProp_GProps props;
BRepGProp::VolumeProperties(shape, props);
return Py::Float(props.Mass());
}
Code: Select all
(Solid_Vol - To_Vol) * S_D
Code: Select all
So_Vol * S_D + To_Vol * To_D
Code: Select all
obj.addProperty("App::PropertyFloat","Density")
obj.Density = 1.0
obj.addProperty("App::PropertyVolume","Mass")
obj.setExpression("Mass",obj.Name+".Shape.Volume * "+obj.Name+".Density")
edwilliams16 wrote: ↑Wed Dec 29, 2021 8:34 pm Another anomaly: If you select a cube, mass and volume are (numerically) equal. If you select an edge of that cube, volume is zero (good), but the mass is (numerically) equal to the length! Select a vertex, volume is zero (good), but mass is undefined! It is hard to make much sense of the mass property.
Code: Select all
return Py::Float(props.Mass());
Sorry, but this does not make sense to me. I have created dozens of (mostly sheet metal) parts that were welded together. But this then becomes an assembly. It doesn't make sense to have one file with bodies that have different density and you combine those two to make a fusion. That belongs in an assembly IMHO.TheMarkster wrote: ↑Mon Dec 27, 2021 9:18 pm There is no Density property I am aware of in FreeCAD. I suppose one could be added where Mass and Volume are defined. Then Mass becomes Volume * Density. The problem is when you start mixing objects of differing densities in boolean operations it becomes complicated to figure out what Density to assign to the boolean result. For example, suppose you have a cylinder of density = 2 and a cube of density = 4 (imagine the cylinder is some light aluminum alloy and the cube is some heavier steel alloy) and you do a boolean union. Which density does the fusion object get? A simple weighted average might work there. Now fillet all the edges. Some material is added in some places, some removed in some places, and it's different densities and we have really no idea which edges were density = 4 and which were density = 2 and which were common to both. Suppose the user then pockets a hole through the cylinder. What will be the density of the new pocket object? Well, we cut through the cylinder, so therefore, the material removed was density = 2, but how do we know the hole was through the cylinder? All FreeCAD would know is the fusion object had a hole cut through it, and not whether the hole went through the lighter cylinder or the heavier cube or through bits of each.
You are most probably right as far as bodies or primitives are concerned. You may be right as far as Booleans are concerned. But you are probably wrong when it comes to compounds and you are definitely wrong when it comes to multiple objects inside of a Part container, leave alone a whole file.
Please quote only what you directly refer to. That keeps topics shorter and improves legibility. Those who want to see more can easily follow the up-arrow link.Or did I make a mistake.