def build_geometry(self, doc): objs = solid_interference_maker(doc) # this box interfere with 2 other boxes, so it should be auto suppressed objs[4].Placement = App.Placement(App.Vector(-4.5, 5, 0), App.Rotation(App.Vector(0, 0, 1), 0)) doc.recompute() return objs
def build_geometry(self, doc): objs = solid_interference_maker(doc) # this box interfere with some other boxes # if it is weak interference, it can fixed autmaitcally # see parameter setting in GeometryImprinter objs[4].Placement = App.Placement(App.Vector(-9.9, -5, 0), App.Rotation(App.Vector(0, 0, 1), 0)) doc.recompute() return objs
def makeBoxLine(doc, N=6): print("a geometry of box in line has been created") length = 10 nBoxes = N # Part.makeBox(length, length, length) boxes = [doc.addObject("Part::Box", "Box") for i in range(nBoxes)] for x in range(N): ind = x boxes[ind].Placement = App.Placement( App.Vector(x * length, 0, 0), App.Rotation(App.Vector(0, 0, 1), 0)) doc.recompute() return boxes
def load_shape(filename): # this function does not work properly on multiple files _, fname = os.path.split(filename) document_name = fname.split(".")[0] App.newDocument(document_name) Part.insert(filename, document_name) # doc = App.getDocument(document_name) obj = App.ActiveDocument.Objects[0] # get the first and only obj for brep print(obj.Label) s = None if hasattr(obj, "Shape"): s = obj.Shape App.closeDocument(App.ActiveDocument.Name) return s # it is possible to return shape after document close
def build_geometry(self, doc): objs = solid_interference_maker(doc) # this box is enclusured in another box without sharing faces objs[4].Height = 9 objs[4].Length = 9 objs[4].Placement = App.Placement(App.Vector(10.5, 10.5, 0.5), App.Rotation(App.Vector(0, 0, 1), 0)) doc.recompute() # this box is coincident with the box with default placement box = doc.addObject("Part::Box", "Box") box.Width = 10 # Y axis length, make the last box smaller, objs.append(box) doc.recompute() return objs
def makeBoxCubes(doc, N=3): print("a geometry of box with 3D stacking has been created") dim = 3 length = 10 nBoxes = N**dim # Part.makeBox(length, length, length) boxes = [doc.addObject("Part::Box", "Box") for i in range(nBoxes)] for z in range(N): for y in range(N): for x in range(N): ind = N**2 * z + N * y + x boxes[ind].Placement = App.Placement( App.Vector(x * length, y * length, z * length), App.Rotation(App.Vector(0, 0, 1), 0), ) doc.recompute() return boxes
def solid_interference_maker(doc): objs = [doc.addObject("Part::Box", "Box") for i in range(4)] # objs[0].ShapeColor = (0.67,0.00,1.00) # move the second and beyond to a place in contact objs[1].Placement = App.Placement(App.Vector(10, 0, 0), App.Rotation(App.Vector(0, 0, 1), 0)) objs[2].Placement = App.Placement(App.Vector(0, 10, 0), App.Rotation(App.Vector(0, 0, 1), 0)) objs[3].Placement = App.Placement(App.Vector(10, 10, 0), App.Rotation(App.Vector(0, 0, 1), 0)) box = doc.addObject("Part::Box", "Box") box.Width = 9 # Y axis length, make the last box smaller, objs.append(box) doc.recompute() return objs
def build_geometry(self, doc): objs = [doc.addObject("Part::Box", "Box") for i in range(4)] # objs[0].ShapeColor = (0.67,0.00,1.00) # move the second and beyond to a place in contact objs[1].Placement = App.Placement(App.Vector(10, 0, 0), App.Rotation(App.Vector(0, 0, 1), 0)) objs[2].Placement = App.Placement(App.Vector(0, 10, 0), App.Rotation(App.Vector(0, 0, 1), 0)) objs[3].Placement = App.Placement(App.Vector(10, 10, 0), App.Rotation(App.Vector(0, 0, 1), 0)) doc.addObject("Part::Cylinder", "Cylinder") doc.Cylinder.Placement = App.Placement( App.Vector(10, 10, 0), App.Rotation(App.Vector(0, 0, 1), 0)) doc.recompute() ret = [] for o in objs: cut = doc.addObject("Part::Cut", "Cut") cut.Base = o cut.Tool = doc.Cylinder ret.append(cut) doc.recompute() c2 = doc.addObject("Part::Cylinder", "Cylinder") c2 = App.ActiveDocument.ActiveObject tol = 1e-4 c2.Placement = App.Placement(App.Vector(10 + tol, 10 + tol, 0), App.Rotation(App.Vector(0, 0, 1), 0)) # print(type(c2), type(doc.Cylinder), c2.Placement) ret.append(doc.Cylinder) # doc.Cylinder is working return ret