def Activated(self): from femtools import femutils overalboundbox = femutils.getBoundBoxOfAllDocumentShapes( FreeCAD.ActiveDocument) # print(overalboundbox) min_bb_length = (min( set([ overalboundbox.XLength, overalboundbox.YLength, overalboundbox.ZLength ]))) dbox = min_bb_length * 0.2 aFace = femutils.getSelectedFace(FreeCADGui.Selection.getSelectionEx()) if aFace: f_CoM = aFace.CenterOfMass f_uvCoM = aFace.Surface.parameter( f_CoM) # u,v at CoM for normalAt calculation f_normal = aFace.normalAt(f_uvCoM[0], f_uvCoM[1]) else: f_CoM = FreeCAD.Vector(0, 0, 0) f_normal = FreeCAD.Vector(0, 0, 1) from pivy import coin coin_normal_vector = coin.SbVec3f(-f_normal.x, -f_normal.y, -f_normal.z) coin_bound_box = coin.SbBox3f(f_CoM.x - dbox, f_CoM.y - dbox, f_CoM.z - dbox * 0.15, f_CoM.x + dbox, f_CoM.y + dbox, f_CoM.z + dbox * 0.15) clip_plane = coin.SoClipPlaneManip() clip_plane.setValue(coin_bound_box, coin_normal_vector, 1) FreeCADGui.ActiveDocument.ActiveView.getSceneGraph().insertChild( clip_plane, 1)
def Activated(self): try: clip_plane = coin.SoClipPlaneManip() clip_plane.setValue(coin.SbBox3f( 4, 4, 4, 8, 8, 8), coin.SbVec3f(-1, -1, -1), 1) Gui.ActiveDocument.ActiveView.getSceneGraph().insertChild(clip_plane, 1) Gui.ActiveDocument.ActiveView.viewAxonometric() Gui.ActiveDocument.ActiveView.fitAll() except Exception as err: App.Console.PrintError("'View Inside objects' Failed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def draw_box(vertices=[], color=(0.0, 0.0, 0.0), LineWidth=1): """ Draw any box. This will be the base of all multi-point drawing. Curves, and arc is not here. """ if len(vertices) < 4: raise ValueError('Vertices must be 4') dash = coin.SoSeparator() v = coin.SoVertexProperty() coords = coin.SoTransform() p1 = vertices[0] p2 = vertices[1] p3 = vertices[2] p4 = vertices[3] square = coin.SbBox3f(p1, p2, p3, p4) square.vertexProperty = v style = coin.SoDrawStyle() style.lineWidth = LineWidth dash.addChild(style) dash.addChild(color) dash.addChild(square) dash.addChild(coords) return draw_square