Code: Select all
FreeCADGui.getDocument("Unnamed").getObject("out").BoundingBox = True
Code: Select all
FreeCADGui.getDocument("Unnamed").getObject("out").BoundingBox = True
Code: Select all
App.ActiveDocument.Box.Shape.BoundBox
Code: Select all
objs = FreeCADGui.Selection.getSelection() # select object with getSelection()
if len(objs) >= 1:
if hasattr(objs[0], "Shape"):
s = objs[0].Shape
elif hasattr(objs[0], "Mesh"): # upgrade with wmayer thanks #http://forum.freecadweb.org/viewtopic.php?f=13&t=22331
s = objs[0].Mesh
elif hasattr(objs[0], "Points"):
s = objs[0].Points
#sel = FreeCADGui.Selection.getSelection() # select object with getSelection()
#boundBox_= sel[0].Shape.BoundBox # BoundBox of the object
boundBox_= s.BoundBox # BoundBox of the object
App.Console.PrintMessage("boundBox_ : "+str(boundBox_)+"\n")
boundBoxLX = boundBox_.XLength # Length x boundBox rectangle
boundBoxLY = boundBox_.YLength # Length y boundBox rectangle
boundBoxLZ = boundBox_.ZLength # Length z boundBox rectangle
boundBoxDiag= boundBox_.DiagonalLength # Diagonal Length boundBox rectangle
App.Console.PrintMessage("boundBoxLX : "+str(boundBoxLX)+"\n")
App.Console.PrintMessage("boundBoxLY : "+str(boundBoxLY)+"\n")
App.Console.PrintMessage("boundBoxLZ : "+str(boundBoxLZ)+"\n")
App.Console.PrintMessage("boundBoxDiag : "+str(boundBoxDiag)+"\n\n")
X*Y*Z ?umardastgir wrote: ↑Tue May 21, 2019 4:11 pm Thanks a lot for your response! How do I calculate the volume though?
Code: Select all
FreeCAD.getDocument("Unnamed").Objects[0].Mesh.Area
FreeCAD.getDocument("Unnamed").Objects[0].Mesh.Volume
Seems correct to me. But nothing better than checking to be sure. Just model a 1 m3 cube, export to STL, then reimport and check your macro on it.umardastgir wrote: ↑Tue May 21, 2019 5:39 pm Volume of the part (stl mesh). And I also need the surface area.
I have done the following:And this does give me the area and volume, but is this the right approach?Code: Select all
FreeCAD.getDocument("Unnamed").Objects[0].Mesh.Area FreeCAD.getDocument("Unnamed").Objects[0].Mesh.Volume
I think Mesh.Volume on meshes returns nothing ?umardastgir wrote: ↑Tue May 21, 2019 5:39 pm Volume of the part (stl mesh). And I also need the surface area.Code: Select all
FreeCAD.getDocument("Unnamed").Objects[0].Mesh.Area FreeCAD.getDocument("Unnamed").Objects[0].Mesh.Volume