def build(self, stacks_to_build: List[str] = [""]): if stacks_to_build == [""]: # build them all by default stacks_to_build = [x["name"] for x in self.stacks] drawing_layers_needed = [] for stack_instructions in self.stacks: if stack_instructions["name"] in stacks_to_build: for stack_layer in stack_instructions["layers"]: drawing_layers_needed += stack_layer["drawing_layer_names"] if "edge_case" in stack_layer: drawing_layers_needed.append(stack_layer["edge_case"]) drawing_layers_needed_unique = list(set(drawing_layers_needed)) # all the wires we'll need here wires = self.get_wires(self.sources, drawing_layers_needed_unique) stacks = {} for stack_instructions in self.stacks: # asy = cadquery.Assembly() asy = None if stack_instructions["name"] in stacks_to_build: # asy.name = stack_instructions["name"] z_base = 0 for stack_layer in stack_instructions["layers"]: t = stack_layer["thickness"] boundary_layer_name = stack_layer["drawing_layer_names"][ 0] # boundary layer must always be the first one listed w0 = wires[boundary_layer_name][0] wp = CQ().sketch().face(w0) for w in wires[boundary_layer_name][1::]: wp = wp.face(w, mode="s") wp = wp.finalize().extrude(t) # the workpiece is now made wp = wp.faces(">Z").sketch() if "array" in stack_layer: array_points = stack_layer["array"] else: array_points = [(0, 0, 0)] for drawing_layer_name in stack_layer[ "drawing_layer_names"][1:]: some_wires = wires[drawing_layer_name] for awire in some_wires: wp = wp.push(array_points).face( awire, mode="a", ignore_selection=False) wp = wp.faces() if "edge_case" in stack_layer: edge_wire = wires[stack_layer["edge_case"]][0] wp = wp.face(edge_wire, mode="i") wp = wp.clean() # wp = wp.finalize().cutThruAll() # this is a fail, but should work wp = wp.finalize().extrude(-t, combine="cut") new = wp.translate([0, 0, z_base]) if asy is None: # some silly hack needed to work around https://github.com/CadQuery/cadquery/issues/993 asy = cadquery.Assembly(new, name=stack_layer["name"], color=cadquery.Color( stack_layer["color"])) # asy.name = stack_instructions["name"] else: asy.add(new, name=stack_layer["name"], color=cadquery.Color(stack_layer["color"])) z_base = z_base + t stacks[stack_instructions["name"]] = asy return stacks
def build(self, stacks_to_build: List[str] = [""]): if stacks_to_build == [""]: # build them all by default stacks_to_build = [x["name"] for x in self.stacks] drawing_layers_needed = [] for stack_instructions in self.stacks: if stack_instructions["name"] in stacks_to_build: for stack_layer in stack_instructions["layers"]: drawing_layers_needed += stack_layer["drawing_layer_names"] if "edge_case" in stack_layer: drawing_layers_needed.append(stack_layer["edge_case"]) drawing_layers_needed_unique = list(set(drawing_layers_needed)) # all the faces we'll need here layers = self.get_layers(self.sources, drawing_layers_needed_unique) self._layers = layers stacks = {} for stack_instructions in self.stacks: asy = cadquery.Assembly() # asy = None if stack_instructions["name"] in stacks_to_build: asy.name = stack_instructions["name"] z_base = 0 for stack_layer in stack_instructions["layers"]: t = stack_layer["thickness"] boundary_layer_name = stack_layer["drawing_layer_names"][ 0] # boundary layer must always be the first one listed layer_comp = cadquery.Compound.makeCompound( layers[boundary_layer_name].faces().vals()) if "array" in stack_layer: array_points = stack_layer["array"] else: array_points = [(0, 0, 0)] if len(stack_layer["drawing_layer_names"]) == 1: wp = CQ().sketch().push(array_points).face( layer_comp, mode="a", ignore_selection=False) else: wp = CQ().sketch().face(layer_comp, mode="a", ignore_selection=False) wp = wp.finalize().extrude( t) # the workpiece base is now made if len(stack_layer["drawing_layer_names"]) > 1: wp = wp.faces(">Z").workplane( centerOption="ProjectedOrigin").sketch() for drawing_layer_name in stack_layer[ "drawing_layer_names"][1:]: layer_comp = cadquery.Compound.makeCompound( layers[drawing_layer_name].faces().vals()) wp = wp.push(array_points).face( layer_comp, mode="a", ignore_selection=False) wp = wp.faces() if "edge_case" in stack_layer: edge_layer_name = stack_layer["edge_case"] layer_comp = cadquery.Compound.makeCompound( layers[edge_layer_name].faces().vals()) es = CQ().sketch().face(layer_comp) wp = wp.face(es.faces(), mode="i") wp = wp.clean() # wp = wp.finalize().cutThruAll() # this is a fail, but should work. if it's not a fail is slower than the below line wp = wp.finalize().extrude(-t, combine="cut") # give option to override calculated z_base if "z_base" in stack_layer: z_base = stack_layer["z_base"] new = wp.translate([0, 0, z_base]) asy.add(new, name=stack_layer["name"], color=cadquery.Color(stack_layer["color"])) z_base = z_base + t stacks[stack_instructions["name"]] = asy return stacks