def create_bar(box_size, bar_lenght, center, name, symmetry_planes=None, mesh_size=None): bar_obj = doc.addObject('Part::Box', name+'_obj') bar_obj.Height = box_size bar_obj.Width = bar_lenght bar_obj.Length = box_size bar_obj.Placement.Base = FreeCAD.Vector(center)- FreeCAD.Vector(box_size/2,0,box_size/2) doc.recompute() bar_obj = reduce_half_symmetry(bar_obj, name, App, doc, planes=symmetry_planes) doc.recompute() face_picks=[] face_picks=[('alpha0',0), ('alpha1',5), ('beta0',3), ('beta1',1), ('gamma0',4), ('gamma1',2)] faces = pick_faces_from_geometry(bar_obj, face_picks) solids = [] add_entity_in_list(solids, name, bar_obj, {'mesh size':mesh_size}) entities_dict = create_entities_dict(name, faces, solids, main_object=bar_obj) return entities_dict
def create_air(coil_inner_radius, coil_outer_radius, coil_height, airgap, z, coil_entities, name, mesh_sizes=None): airpluscoil_entities = create_coil(coil_inner_radius - airgap, coil_outer_radius + airgap, coil_height + airgap * 2, z, name="air and coil", face_entities=False) air = doc.addObject("Part::Cut", "air" + '_obj') air.Base = airpluscoil_entities['main object'] air.Tool = coil_entities['main object'] doc.recompute() # Here we define the entities dictionary. face_picks = [('xy0', 3), ('xy0', 4), ('cylinder_lateral_surface', 5)] faces = pick_faces_from_geometry(air, face_picks) solids = [] add_entity_in_list(solids, name, air, mesh_sizes=mesh_sizes) entities_out = create_entities_dict(name, faces, solids, main_object=air) return entities_out
def create_core(h, w, a, b, name, mesh_sizes=None): core = doc.addObject('PartDesign::Body', name + '_obj') sketch = core.newObject('Sketcher::SketchObject', name + ' sketch') #sketch.Support = (doc.XY_Plane, ['']) sketch.MapMode = 'FlatFace' sketch.addGeometry( Part.LineSegment(App.Vector(0, -h / 2, 0), App.Vector(0, h / 2, 0)), False) sketch.addGeometry( Part.LineSegment(App.Vector(0, h / 2, 0), App.Vector(w / 2, h / 2, 0)), False) sketch.addGeometry( Part.LineSegment(App.Vector(w / 2, h / 2, 0), App.Vector(w / 2, a / 2, 0)), False) sketch.addGeometry( Part.LineSegment(App.Vector(w / 2, a / 2, 0), App.Vector(b / 2, a / 2, 0)), False) sketch.addGeometry( Part.LineSegment(App.Vector(b / 2, a / 2, 0), App.Vector(b / 2, -a / 2, 0)), False) sketch.addGeometry( Part.LineSegment(App.Vector(b / 2, -a / 2, 0), App.Vector(w / 2, -a / 2, 0)), False) sketch.addGeometry( Part.LineSegment(App.Vector(w / 2, -a / 2, 0), App.Vector(w / 2, -h / 2, 0)), False) sketch.addGeometry( Part.LineSegment(App.Vector(w / 2, -h / 2, 0), App.Vector(0, -h / 2, 0)), False) doc.recompute() fit_view() rev = core.newObject("PartDesign::Revolution", name + " rev") rev.Profile = sketch rev.ReferenceAxis = (sketch, ['V_Axis']) rev.Angle = 180 rev.Reversed = 1 doc.recompute() # #fit_view() # Here we define the entities dictionary. face_picks = [('infinity_xz0', 6), ('infinity_xz1', 0), ('cylinder_lateral_surface', 1), ('cylinder_lateral_surface', 5), ('xy0', 7), ('xy0', 8)] faces = pick_faces_from_geometry(core, face_picks) solids = [] add_entity_in_list(solids, name, core, mesh_sizes=mesh_sizes) entities_out = create_entities_dict(name, faces, solids, main_object=core) return entities_out
def create_coil(r, R, h, z, name, face_entities=True, mesh_sizes=None): coil = doc.addObject('PartDesign::Body', name + '_obj') sketch = coil.newObject('Sketcher::SketchObject', name + ' sketch') #sketch.Support = (doc.XY_Plane, ['']) sketch.MapMode = 'FlatFace' sketch.addGeometry( Part.LineSegment(App.Vector(r, -h / 2 + z, 0), App.Vector(r, h / 2 + z, 0)), False) sketch.addGeometry( Part.LineSegment(App.Vector(r, h / 2 + z, 0), App.Vector(R, h / 2 + z, 0)), False) sketch.addGeometry( Part.LineSegment(App.Vector(R, h / 2 + z, 0), App.Vector(R, -h / 2 + z, 0)), False) sketch.addGeometry( Part.LineSegment(App.Vector(R, -h / 2 + z, 0), App.Vector(r, -h / 2 + z, 0)), False) doc.recompute() fit_view() rev = coil.newObject("PartDesign::Revolution", name + " rev") rev.Profile = sketch rev.ReferenceAxis = (sketch, ['V_Axis']) rev.Angle = 180 rev.Reversed = 1 doc.recompute() coil_faces = coil.Shape.Faces # Here we define the entities dictionary. Note that each coil contain the same # names for each geometric entity. That is why the 'name' key is required # in the dictionary. # Naming of the faces can be avoided by giving face_entities=False as argument faces = [] if (face_entities): face_picks = [('gamma0', 4), ('gamma1', 5)] faces = pick_faces_from_geometry(coil, face_picks) solids = [] add_entity_in_list(solids, name, coil, mesh_sizes=mesh_sizes) entities_out = create_entities_dict(name, faces, solids, main_object=coil) return entities_out