upgrade getBoundBoxOfAllDocumentShapes to handle more objects

This commit is contained in:
UR-0
2021-02-10 12:17:25 +01:00
committed by Bernd Hahnebach
parent de9329a6c1
commit 31ca5bc02e
2 changed files with 33 additions and 22 deletions

View File

@@ -83,13 +83,17 @@ class _ClippingPlaneAdd(CommandManager):
from femtools.femutils import getBoundBoxOfAllDocumentShapes
from femtools.femutils import getSelectedFace
overalboundbox = getBoundBoxOfAllDocumentShapes(FreeCAD.ActiveDocument)
# print(overalboundbox)
min_bb_length = (min(set([
overalboundbox.XLength,
overalboundbox.YLength,
overalboundbox.ZLength
])))
overallboundbox = getBoundBoxOfAllDocumentShapes(FreeCAD.ActiveDocument)
# print(overallboundbox)
if overallboundbox:
min_bb_length = (min(set([
overallboundbox.XLength,
overallboundbox.YLength,
overallboundbox.ZLength
])))
else:
min_bb_length = 10. # default
dbox = min_bb_length * 0.2
aFace = getSelectedFace(FreeCADGui.Selection.getSelectionEx())

View File

@@ -268,30 +268,37 @@ def getBoundBoxOfAllDocumentShapes(doc):
Part and PartDesign objects). If the document contains no such objects or
no objects at all return ``None``.
"""
overalboundbox = None
overallboundbox = None
# netgen mesh obj has an attribute Shape which is an Document obj, which has no BB
# a FemMesh without a Shape could be clipped too
# https://forum.freecadweb.org/viewtopic.php?f=18&t=52920
for o in doc.Objects:
bb = None
if hasattr(o, "Shape") and hasattr(o.Shape, "BoundBox"):
try:
bb = o.Shape.BoundBox
except Exception:
pass
elif hasattr(o, "FemMesh") and hasattr(o.FemMesh, "BoundBox"):
try:
bb = o.FemMesh.BoundBox
except Exception:
pass
Types = ["Shape", "FemMesh", "Mesh", "Points"]
for Type in Types:
FreeCAD.Console.PrintMessage("trying: " + str(o) + ":" + Type + "\n") # debug only
if hasattr(o, Type):
try:
bb = getattr(getattr(o,Type),"BoundBox")
FreeCAD.Console.PrintMessage(str(bb) + "\n") # debug only
break
except Exception:
FreeCAD.Console.PrintMessage("exception \n") # debug only
pass
if bb:
if bb.isValid():
if not overalboundbox:
overalboundbox = bb
if not overallboundbox:
overallboundbox = bb
else:
overalboundbox.add(bb)
return overalboundbox
overallboundbox.add(bb)
else: # debug only
FreeCAD.Console.PrintMessage("no bb\n") # debug only
FreeCAD.Console.PrintMessage(str(overallboundbox) + "\n") # debug only
return overallboundbox
def getSelectedFace(selectionex):