From 9f7c6061727d81281cebeb574f93f284c4c0ee60 Mon Sep 17 00:00:00 2001 From: vectronic Date: Mon, 20 Jul 2020 19:58:00 +0100 Subject: [PATCH] fix: edge selection for trimming fixed fix: constraint calculation resolved by recomputing before rectangulararray refactor: open studs converted to pad followed by pocket --- Legify/Body.py | 31 +++--- Legify/Common.py | 241 ++++++++++++++++++++++++-------------------- Legify/Holes.py | 7 +- Legify/SideStuds.py | 82 +++++++++++---- Legify/TopStuds.py | 96 ++++++++++++------ 5 files changed, 276 insertions(+), 181 deletions(-) diff --git a/Legify/Body.py b/Legify/Body.py index bf4af85..5dba317 100644 --- a/Legify/Body.py +++ b/Legify/Body.py @@ -545,20 +545,20 @@ def _render_tubes(self): # Outer circle add_circle_to_sketch(tubes_pad_sketch, DIMS_TUBE_OUTER_RADIUS, 0.5 * DIMS_STUD_SPACING, - 0.5 * DIMS_STUD_SPACING) + 0.5 * DIMS_STUD_SPACING, False) + + self.doc.recompute() # create array if needed if self.width > 2 or self.depth > 2: geometry_indices = [range(0, len(tubes_pad_sketch.Geometry) - 1)] - if self.width == 2 and self.depth > 2: - tubes_pad_sketch.addRectangularArray(geometry_indices, Vector(0, DIMS_STUD_SPACING, 0), False, - self.depth - 1, self.width - 1, True) - elif self.width > 2 and self.depth == 2: + if self.width > 2 and self.depth == 2: tubes_pad_sketch.addRectangularArray(geometry_indices, Vector(DIMS_STUD_SPACING, 0, 0), False, self.width - 1, self.depth - 1, True) else: tubes_pad_sketch.addRectangularArray(geometry_indices, Vector(0, DIMS_STUD_SPACING, 0), False, self.depth - 1, self.width - 1, True) + self.doc.recompute() tubes_pad = self.brick.newObject("PartDesign::Pad", "tubes_pad") tubes_pad.Type = PAD_TYPE_UP_TO_FACE @@ -574,23 +574,22 @@ def _render_tubes(self): tubes_pocket_sketch.Support = (self.top_inside_datum_plane, '') tubes_pocket_sketch.MapMode = 'FlatFace' - add_outer_circle_and_inner_circle_with_flats_to_sketch(tubes_pocket_sketch, DIMS_TUBE_OUTER_RADIUS, - DIMS_TUBE_INNER_RADIUS, DIMS_STUD_FLAT_THICKNESS, False, - 0.5 * DIMS_STUD_SPACING, - 0.5 * DIMS_STUD_SPACING) + add_inner_circle_with_flats_to_sketch(tubes_pocket_sketch, DIMS_TUBE_OUTER_RADIUS, + DIMS_TUBE_INNER_RADIUS, DIMS_STUD_FLAT_THICKNESS, + 0.5 * DIMS_STUD_SPACING, + 0.5 * DIMS_STUD_SPACING) + self.doc.recompute() # create array if needed if self.width > 2 or self.depth > 2: geometry_indices = [range(0, len(tubes_pocket_sketch.Geometry) - 1)] - if self.width == 2 and self.depth > 2: - tubes_pocket_sketch.addRectangularArray(geometry_indices, Vector(0, DIMS_STUD_SPACING, 0), False, - self.depth - 1, self.width - 1, True) - elif self.width > 2 and self.depth == 2: + if self.width > 2 and self.depth == 2: tubes_pocket_sketch.addRectangularArray(geometry_indices, Vector(DIMS_STUD_SPACING, 0, 0), False, self.width - 1, self.depth - 1, True) else: tubes_pocket_sketch.addRectangularArray(geometry_indices, Vector(0, DIMS_STUD_SPACING, 0), False, self.depth - 1, self.width - 1, True) + self.doc.recompute() tubes_pocket = self.brick.newObject("PartDesign::Pocket", "tubes_pocket") tubes_pocket.Type = POCKET_TYPE_THROUGH_ALL @@ -697,12 +696,15 @@ def _render_sticks(self): sticks_pad_sketch.addGeometry(geometries, False) sticks_pad_sketch.addConstraint(constraints) + self.doc.recompute() + if self.width > 1: sticks_pad_sketch.addRectangularArray([0], Vector(DIMS_STUD_SPACING, 0, 0), False, self.width - 1, 1, True) else: sticks_pad_sketch.addRectangularArray([0], Vector(0, DIMS_STUD_SPACING, 0), False, self.depth - 1, 1, True) + self.doc.recompute() sticks_pad = self.brick.newObject("PartDesign::Pad", "sticks_pad") sticks_pad.Type = PAD_TYPE_UP_TO_FACE @@ -745,12 +747,15 @@ def _render_sticks(self): sticks_pocket_sketch.addGeometry(geometries, False) sticks_pocket_sketch.addConstraint(constraints) + self.doc.recompute() + if self.width > 1: sticks_pocket_sketch.addRectangularArray([0], Vector(DIMS_STUD_SPACING, 0, 0), False, self.width - 1, 1, True) if self.depth > 1: sticks_pocket_sketch.addRectangularArray([0], Vector(0, DIMS_STUD_SPACING, 0), False, self.depth - 1, 1, True) + self.doc.recompute() sticks_pocket = self.brick.newObject("PartDesign::Pocket", "sticks_pocket") sticks_pocket.Type = POCKET_TYPE_THROUGH_ALL diff --git a/Legify/Common.py b/Legify/Common.py index 34b684e..7374021 100644 --- a/Legify/Common.py +++ b/Legify/Common.py @@ -140,30 +140,88 @@ def yz_plane_bottom_left_vector(): return Vector(0, -1, -1) -def add_circle_to_sketch(sketch, radius, x, y): - Console.PrintMessage("add_circle_to_sketch({0})\n".format(radius)) +def add_circle_to_sketch(sketch, radius, x, y, as_arcs): + Console.PrintMessage("add_circle_to_sketch({0},{1},{2},{3})\n".format(radius, x, y, as_arcs)) geometries = [] constraints = [] - geometries.append(Part.Circle()) - constraints.append(Sketcher.Constraint("Radius", 0, radius)) - constraints.append(Sketcher.Constraint("DistanceX", SKETCH_GEOMETRY_ORIGIN_INDEX, - SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, - SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, x)) - constraints.append(Sketcher.Constraint("DistanceY", SKETCH_GEOMETRY_ORIGIN_INDEX, - SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, - SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, y)) + if as_arcs: - sketch.addGeometry(geometries, False) - sketch.addConstraint(constraints) + # Construction line + geometries.append(Part.LineSegment(xy_plane_bottom_left_vector(), xy_plane_top_right_vector())) + constraints.append(Sketcher.Constraint('Angle', 0, 45 * math.pi / 180)) + constraints.append(Sketcher.Constraint("DistanceX", + SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, + 0, SKETCH_GEOMETRY_VERTEX_END_INDEX, + x)) + constraints.append(Sketcher.Constraint("DistanceY", + SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, + 0, SKETCH_GEOMETRY_VERTEX_END_INDEX, + y)) + constraints.append(Sketcher.Constraint("Distance", + 0, SKETCH_GEOMETRY_VERTEX_START_INDEX, + 0, SKETCH_GEOMETRY_VERTEX_END_INDEX, + radius)) + # Drawn as two arcs instead of one circle so that an edge appears in geometry - this allows + # measurement between vertices of distance between arc and flat edge + rad1 = 135 * math.pi / 180 + rad2 = 445 * math.pi / 180 + rad3 = 45 * math.pi / 180 + rad4 = 225 * math.pi / 180 + + # arcs + geometries.append(Part.ArcOfCircle(Part.Circle(Vector(4, 4, 0), Vector(0, 0, 1), radius), rad1, rad2)) + geometries.append(Part.ArcOfCircle(Part.Circle(Vector(4, 4, 0), Vector(0, 0, 1), radius), rad3, rad4)) -def add_outer_circle_and_inner_circle_with_flats_to_sketch(sketch, outer_radius, inner_radius, flat_thickness, - outer_circle_is_required, x_offset, y_offset): - Console.PrintMessage("add_outer_circle_and_inner_circle_with_flats_to_sketch({0},{1},{2},{3},{4},{5})\n" - .format(outer_radius, inner_radius, flat_thickness, outer_circle_is_required, - x_offset, y_offset)) + # position arc midpoints + + constraints.append(Sketcher.Constraint('Coincident', + 1, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, + 2, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX)) + constraints.append(Sketcher.Constraint('Coincident', + 0, SKETCH_GEOMETRY_VERTEX_END_INDEX, + 1, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX)) + # join arc endpoints + constraints.append(Sketcher.Constraint('Coincident', + 1, SKETCH_GEOMETRY_VERTEX_END_INDEX, + 2, SKETCH_GEOMETRY_VERTEX_START_INDEX)) + constraints.append(Sketcher.Constraint('Coincident', + 1, SKETCH_GEOMETRY_VERTEX_START_INDEX, + 2, SKETCH_GEOMETRY_VERTEX_END_INDEX)) + # make arcs symmetric on construction line + constraints.append(Sketcher.Constraint('Coincident', + 1, SKETCH_GEOMETRY_VERTEX_START_INDEX, + 0, SKETCH_GEOMETRY_VERTEX_START_INDEX)) + constraints.append(Sketcher.Constraint('Symmetric', + 1, SKETCH_GEOMETRY_VERTEX_START_INDEX, + 1, SKETCH_GEOMETRY_VERTEX_END_INDEX, + 1, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX)) + + sketch.addGeometry(geometries, False) + sketch.addConstraint(constraints) + + # Set construction lines + sketch.toggleConstruction(0) + else: + geometries.append(Part.Circle()) + constraints.append(Sketcher.Constraint("Radius", 0, radius)) + constraints.append(Sketcher.Constraint("DistanceX", + SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, + 0, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, + x)) + constraints.append(Sketcher.Constraint("DistanceY", + SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, + 0, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, + y)) + sketch.addGeometry(geometries, False) + sketch.addConstraint(constraints) + + +def add_inner_circle_with_flats_to_sketch(sketch, outer_radius, inner_radius, flat_thickness, x_offset, y_offset): + Console.PrintMessage("add_inner_circle_with_flats_to_sketch({0},{1},{2},{3},{4})\n" + .format(outer_radius, inner_radius, flat_thickness, x_offset, y_offset)) geometries = [] constraints = [] @@ -210,6 +268,39 @@ def add_outer_circle_and_inner_circle_with_flats_to_sketch(sketch, outer_radius, geometries.append(Part.ArcOfCircle(Part.Circle(Vector(4, 4, 0), Vector(0, 0, 1), inner_radius), rad5, rad6)) geometries.append(Part.ArcOfCircle(Part.Circle(Vector(4, 4, 0), Vector(0, 0, 1), inner_radius), rad7, rad8)) + # Lines equal + constraints.append(Sketcher.Constraint('Equal', 1, 2)) + constraints.append(Sketcher.Constraint('Equal', 1, 3)) + constraints.append(Sketcher.Constraint('Equal', 1, 4)) + + # Lines parallel/perpendicular to construction line + # Use angle constrain instead of parallel/perpendicular so that they + # can't 'flip' and fail to resolve the constraints + constraints.append(Sketcher.Constraint('Angle', 1, 135 * math.pi / 180)) + constraints.append(Sketcher.Constraint('Angle', 2, 45 * math.pi / 180)) + constraints.append(Sketcher.Constraint('Angle', 3, -45 * math.pi / 180)) + constraints.append(Sketcher.Constraint('Angle', 4, -135 * math.pi / 180)) + + # All arcs centred + constraints.append(Sketcher.Constraint('Coincident', + 5, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, + 0, SKETCH_GEOMETRY_VERTEX_END_INDEX)) + constraints.append(Sketcher.Constraint('Coincident', + 6, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, + 0, SKETCH_GEOMETRY_VERTEX_END_INDEX)) + constraints.append(Sketcher.Constraint('Coincident', + 7, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, + 0, SKETCH_GEOMETRY_VERTEX_END_INDEX)) + constraints.append(Sketcher.Constraint('Coincident', + 8, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, + 0, SKETCH_GEOMETRY_VERTEX_END_INDEX)) + + # All equal radius arcs + constraints.append(Sketcher.Constraint('Radius', 5, inner_radius)) + constraints.append(Sketcher.Constraint('Equal', 5, 6)) + constraints.append(Sketcher.Constraint('Equal', 5, 7)) + constraints.append(Sketcher.Constraint('Equal', 5, 8)) + # Link arcs to segments constraints.append(Sketcher.Constraint('Coincident', 1, SKETCH_GEOMETRY_VERTEX_START_INDEX, @@ -236,76 +327,9 @@ def add_outer_circle_and_inner_circle_with_flats_to_sketch(sketch, outer_radius, 4, SKETCH_GEOMETRY_VERTEX_END_INDEX, 8, SKETCH_GEOMETRY_VERTEX_END_INDEX)) - # Lines equal and parallel/perpendicular - constraints.append(Sketcher.Constraint('Equal', 1, 2)) - constraints.append(Sketcher.Constraint('Equal', 1, 3)) - constraints.append(Sketcher.Constraint('Equal', 1, 4)) - constraints.append(Sketcher.Constraint('Parallel', 1, 3)) - constraints.append(Sketcher.Constraint('Parallel', 2, 4)) - constraints.append(Sketcher.Constraint('Perpendicular', 1, 2)) - - # Parallel to tangent line as - constraints.append(Sketcher.Constraint('Parallel', 0, 2)) - - # All arcs centred - constraints.append(Sketcher.Constraint('Coincident', - 5, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, - 0, SKETCH_GEOMETRY_VERTEX_END_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', - 6, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, - 0, SKETCH_GEOMETRY_VERTEX_END_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', - 7, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, - 0, SKETCH_GEOMETRY_VERTEX_END_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', - 8, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, - 0, SKETCH_GEOMETRY_VERTEX_END_INDEX)) - - # All equal radius arcs - constraints.append(Sketcher.Constraint('Radius', 5, inner_radius)) - constraints.append(Sketcher.Constraint('Equal', 5, 6)) - constraints.append(Sketcher.Constraint('Equal', 5, 7)) - constraints.append(Sketcher.Constraint('Equal', 5, 8)) - # The critical measurement: distance to end of construction line constraints.append(Sketcher.Constraint('Distance', 0, SKETCH_GEOMETRY_VERTEX_START_INDEX, 1, flat_thickness)) - # Outer circle - if outer_circle_is_required: - - # Drawn as two arcs instead of one circle so that an edge appears in geometry - this allows - # measurement between vertices of distance between arc and flat edge - rad1 = 135 * math.pi / 180 - rad2 = 445 * math.pi / 180 - rad3 = 45 * math.pi / 180 - rad4 = 225 * math.pi / 180 - - # arcs - geometries.append(Part.ArcOfCircle(Part.Circle(Vector(4, 4, 0), Vector(0, 0, 1), outer_radius), rad1, rad2)) - geometries.append(Part.ArcOfCircle(Part.Circle(Vector(4, 4, 0), Vector(0, 0, 1), outer_radius), rad3, rad4)) - - # join arc endpoints - constraints.append(Sketcher.Constraint('Coincident', - 9, SKETCH_GEOMETRY_VERTEX_END_INDEX, - 10, SKETCH_GEOMETRY_VERTEX_START_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', - 9, SKETCH_GEOMETRY_VERTEX_START_INDEX, - 10, SKETCH_GEOMETRY_VERTEX_END_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', - 0, SKETCH_GEOMETRY_VERTEX_START_INDEX, - 9, SKETCH_GEOMETRY_VERTEX_START_INDEX)) - constraints.append(Sketcher.Constraint('Symmetric', - 9, SKETCH_GEOMETRY_VERTEX_START_INDEX, - 9, SKETCH_GEOMETRY_VERTEX_END_INDEX, - 5, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX)) - # position arc midpoints - constraints.append(Sketcher.Constraint('Coincident', - 0, SKETCH_GEOMETRY_VERTEX_END_INDEX, - 9, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', - 0, SKETCH_GEOMETRY_VERTEX_END_INDEX, - 10, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX)) - sketch.addGeometry(geometries, False) sketch.addConstraint(constraints) @@ -314,8 +338,7 @@ def add_outer_circle_and_inner_circle_with_flats_to_sketch(sketch, outer_radius, def get_circle_edge_names(plane, inverted, offset, feature, radius): - Console.PrintMessage("get_circle_edge_names({0},{1},{2},{3},{4})\n" - .format(plane, inverted, offset, feature, radius)) + Console.PrintMessage("get_circle_edge_names({0},{1},{2},{3})\n".format(plane, inverted, offset, radius)) plane_normal = plane.Shape.normalAt(0, 0) plane_normal = plane_normal if inverted else plane_normal.negative() @@ -366,8 +389,7 @@ def get_circle_edge_names(plane, inverted, offset, feature, radius): def get_arc_edge_names(plane, inverted, offset, feature, radius): - Console.PrintMessage("get_arc_edge_names({0},{1},{2},{3},{4})\n" - .format(plane, inverted, offset, feature, radius)) + Console.PrintMessage("get_arc_edge_names({0},{1},{2})\n".format(inverted, offset, radius)) plane_normal = plane.Shape.normalAt(0, 0) plane_normal = plane_normal if inverted else plane_normal.negative() @@ -382,36 +404,33 @@ def get_arc_edge_names(plane, inverted, offset, feature, radius): face_normal = face.normalAt(0, 0) if face_normal.isEqual(plane_normal, 1e-7): - # desired faces have am arc edge + # desired faces have an arc edge for j in range(0, len(face.Edges)): edge = face.Edges[j] - # arcs have two vertices - if len(edge.Vertexes) == 2: + # arcs have two vertices and arc needs to have a curve with desired radius + if len(edge.Vertexes) == 2 and hasattr(edge, 'Curve') and hasattr(edge.Curve, 'Radius')\ + and abs(edge.Curve.Radius - radius) < 1e-4: - # arc needs to have a curve with desired radius - if hasattr(edge, 'Curve') and hasattr(edge.Curve, 'Radius') and edge.Curve.Radius == radius: + # face with negative offset along normal lies in plane + offset_centre = edge.Vertexes[0].Point - (offset * face_normal) - # face with negative offset along normal lies in plane - offset_centre = edge.Vertexes[0].Point - (offset * face_normal) - - if plane.Shape.isInside(offset_centre, 1e-7, True): - potential_edges.append(edge) + if plane.Shape.isInside(offset_centre, 1e-6, True): + potential_edges.append(edge) for i in range(0, len(feature.Shape.Edges)): edge = feature.Shape.Edges[i] - # arcs have two vertices - if len(edge.Vertexes) == 2: - - # arc needs to have a curve with desired radius - if hasattr(edge, 'Curve') and hasattr(edge.Curve, 'Radius') and edge.Curve.Radius == radius: - - # arc needs to be in potential edges - for j in range(0, len(potential_edges)): - potential_edge = potential_edges[j] - c1 = potential_edge.Curve - c2 = edge.Curve - if c1.Center == c2.Center and c1.Axis == c2.Axis: - edge_names.append("Edge" + repr(i + 1)) + # arcs have two vertices and arc needs to have a curve with desired radius + if len(edge.Vertexes) == 2 and hasattr(edge, 'Curve') and hasattr(edge.Curve, 'Radius')\ + and abs(edge.Curve.Radius - radius) < 1e-4: + + # arc needs to be in potential edges + for j in range(0, len(potential_edges)): + potential_edge = potential_edges[j] + c1 = potential_edge.Curve + c2 = edge.Curve + if c1.Center == c2.Center and c1.Axis == c2.Axis: + edge_names.append("Edge" + repr(i + 1)) + break return edge_names diff --git a/Legify/Holes.py b/Legify/Holes.py index 1679435..21bb640 100644 --- a/Legify/Holes.py +++ b/Legify/Holes.py @@ -121,7 +121,8 @@ def _render_holes(self): # TODO: if/else render axle cross-section # self._add_axle_hole_sketch(geometries, constraints, hole_offset + (i * DIMS_STUD_SPACING)) add_circle_to_sketch(holes_pocket_sketch, DIMS_TECHNIC_HOLE_INNER_RADIUS, hole_offset, - DIMS_TECHNIC_HOLE_CENTRE_HEIGHT) + DIMS_TECHNIC_HOLE_CENTRE_HEIGHT, False) + self.doc.recompute() # create array if needed if hole_count > 1: @@ -147,7 +148,8 @@ def _render_holes(self): holes_counterbore_pocket_sketch.MapMode = 'FlatFace' add_circle_to_sketch(holes_counterbore_pocket_sketch, DIMS_TECHNIC_HOLE_COUNTERBORE_RADIUS, hole_offset, - DIMS_TECHNIC_HOLE_CENTRE_HEIGHT) + DIMS_TECHNIC_HOLE_CENTRE_HEIGHT, False) + self.doc.recompute() # create array if needed if hole_count > 1: @@ -187,6 +189,7 @@ def _render_holes(self): hole_counterbore_fillets.Base = (holes_counterbore_mirror, edge_names) self.doc.recompute() + holes_counterbore_pocket_sketch.ViewObject.Visibility = False def render(self, context): diff --git a/Legify/SideStuds.py b/Legify/SideStuds.py index c08db5d..cc1c061 100644 --- a/Legify/SideStuds.py +++ b/Legify/SideStuds.py @@ -27,8 +27,8 @@ def __init__(self): self.left_datum_plane = None self.right_datum_plane = None - def _render_side_studs_outside(self, label, plane, count, inverted): - Console.PrintMessage("render_side_studs_outside({0},{1})\n".format(label, count)) + def _render_side_studs_outside(self, label, plane, count, style, inverted): + Console.PrintMessage("render_side_studs_outside({0},{1},{2},{3})\n".format(label, count, style, inverted)) # side studs outside pad @@ -37,9 +37,10 @@ def _render_side_studs_outside(self, label, plane, count, inverted): side_studs_outside_pad_sketch.Support = (plane, '') side_studs_outside_pad_sketch.MapMode = 'FlatFace' - add_outer_circle_and_inner_circle_with_flats_to_sketch(side_studs_outside_pad_sketch, DIMS_STUD_OUTER_RADIUS, - DIMS_STUD_INNER_RADIUS, DIMS_STUD_FLAT_THICKNESS, True, - 0, DIMS_SIDE_STUD_CENTRE_HEIGHT) + add_circle_to_sketch(side_studs_outside_pad_sketch, DIMS_STUD_OUTER_RADIUS, 0, + DIMS_SIDE_STUD_CENTRE_HEIGHT, True) + + self.doc.recompute() # create array if needed if count > 1: @@ -47,6 +48,7 @@ def _render_side_studs_outside(self, label, plane, count, inverted): side_studs_outside_pad_sketch.addRectangularArray(geometry_indices, Vector(DIMS_STUD_SPACING, 0, 0), False, count, 1, True) + self.doc.recompute() side_studs_outside_pad = self.brick.newObject("PartDesign::Pad", label + "_side_studs_outside_pad") side_studs_outside_pad.Type = PAD_TYPE_DIMENSION @@ -56,17 +58,51 @@ def _render_side_studs_outside(self, label, plane, count, inverted): self.doc.recompute() + side_studs_outside_pad_sketch.ViewObject.Visibility = False + # determine the stud outer edges - # edge_names = get_arc_edge_names(plane, inverted, DIMS_STUD_HEIGHT, side_studs_outside_pad, - # DIMS_STUD_OUTER_RADIUS) - # - # # side studs outer fillet - # side_stud_outer_fillets = self.brick.newObject("PartDesign::Fillet", label + "_side_stud_outer_fillets") - # side_stud_outer_fillets.Radius = DIMS_STUD_FILLET - # side_stud_outer_fillets.Base = (side_studs_outside_pad, edge_names) - # - # self.doc.recompute() - # side_studs_outside_pad_sketch.ViewObject.Visibility = False + edge_names = get_arc_edge_names(plane, inverted, DIMS_STUD_HEIGHT, side_studs_outside_pad, + DIMS_STUD_OUTER_RADIUS) + + if len(edge_names) > 0: + + # side studs outer fillet + side_stud_outer_fillets = self.brick.newObject("PartDesign::Fillet", label + "_side_stud_outer_fillets") + side_stud_outer_fillets.Radius = DIMS_STUD_FILLET + side_stud_outer_fillets.Base = (side_studs_outside_pad, edge_names) + + self.doc.recompute() + + # side studs outside pocket + + side_studs_outside_pocket_sketch = self.brick.newObject("Sketcher::SketchObject", + label + "_side_studs_outside_pocket_sketch") + side_studs_outside_pocket_sketch.Support = (plane, '') + side_studs_outside_pocket_sketch.MapMode = 'FlatFace' + + add_inner_circle_with_flats_to_sketch(side_studs_outside_pocket_sketch, DIMS_STUD_OUTER_RADIUS, + DIMS_STUD_INNER_RADIUS, DIMS_STUD_FLAT_THICKNESS, + 0, DIMS_SIDE_STUD_CENTRE_HEIGHT) + self.doc.recompute() + + # create array if needed + if count > 1: + geometry_indices = [range(0, len(side_studs_outside_pocket_sketch.Geometry) - 1)] + side_studs_outside_pocket_sketch.addRectangularArray(geometry_indices, + Vector(DIMS_STUD_SPACING, 0, 0), False, + count, 1, True) + self.doc.recompute() + + side_studs_outside_pocket = self.brick.newObject("PartDesign::Pocket", + label + "_side_studs_outside_pocket") + side_studs_outside_pocket.Type = PAD_TYPE_DIMENSION + side_studs_outside_pocket.Profile = side_studs_outside_pocket_sketch + side_studs_outside_pocket.Length = DIMS_STUD_HEIGHT + side_studs_outside_pocket.Reversed = True if inverted else False + + self.doc.recompute() + + side_studs_outside_pocket_sketch.ViewObject.Visibility = False def _render_side_studs_inside(self, label, plane, count, inverted): Console.PrintMessage("render_side_studs_inside({0},{1})\n".format(label, count)) @@ -78,9 +114,10 @@ def _render_side_studs_inside(self, label, plane, count, inverted): side_studs_inside_pocket_sketch.Support = (plane, '') side_studs_inside_pocket_sketch.MapMode = 'FlatFace' - add_outer_circle_and_inner_circle_with_flats_to_sketch(side_studs_inside_pocket_sketch, DIMS_STUD_OUTER_RADIUS, - DIMS_STUD_INNER_RADIUS, DIMS_STUD_FLAT_THICKNESS, False, - 0, DIMS_SIDE_STUD_CENTRE_HEIGHT) + add_inner_circle_with_flats_to_sketch(side_studs_inside_pocket_sketch, DIMS_STUD_OUTER_RADIUS, + DIMS_STUD_INNER_RADIUS, DIMS_STUD_FLAT_THICKNESS, + 0, DIMS_SIDE_STUD_CENTRE_HEIGHT) + self.doc.recompute() # create array if needed if count > 1: @@ -88,6 +125,7 @@ def _render_side_studs_inside(self, label, plane, count, inverted): side_studs_inside_pocket_sketch.addRectangularArray(geometry_indices, Vector(DIMS_STUD_SPACING, 0, 0), False, count, 1, True) + self.doc.recompute() side_studs_inside_pocket = self.brick.newObject("PartDesign::Pocket", label + "_side_studs_inside_pocket") side_studs_inside_pocket.Type = POCKET_TYPE_DIMENSION @@ -118,21 +156,21 @@ def render(self, context): self.right_datum_plane = context.right_datum_plane if self.front: - self._render_side_studs_outside("front", self.front_datum_plane, self.width, True) + self._render_side_studs_outside("front", self.front_datum_plane, self.width, self.style, True) if self.style == SideStudStyle.HOLE: self._render_side_studs_inside("front", self.front_datum_plane, self.width, False) if self.back: - self._render_side_studs_outside("back", self.back_datum_plane, self.width, False) + self._render_side_studs_outside("back", self.back_datum_plane, self.width, self.style, False) if self.style == SideStudStyle.HOLE: self._render_side_studs_inside("back", self.back_datum_plane, self.width, True) if self.left: - self._render_side_studs_outside("left", self.left_datum_plane, self.depth, False) + self._render_side_studs_outside("left", self.left_datum_plane, self.depth, self.style, False) if self.style == SideStudStyle.HOLE: self._render_side_studs_inside("left", self.left_datum_plane, self.depth, True) if self.right: - self._render_side_studs_outside("right", self.right_datum_plane, self.depth, True) + self._render_side_studs_outside("right", self.right_datum_plane, self.depth, self.style, True) if self.style == SideStudStyle.HOLE: self._render_side_studs_inside("right", self.right_datum_plane, self.depth, False) diff --git a/Legify/TopStuds.py b/Legify/TopStuds.py index af4a53b..9eaf8ac 100644 --- a/Legify/TopStuds.py +++ b/Legify/TopStuds.py @@ -33,23 +33,15 @@ def _render_top_studs_outside(self, initial_width_offset, initial_depth_offset, top_studs_outside_pad_sketch.Support = (self.top_datum_plane, '') top_studs_outside_pad_sketch.MapMode = 'FlatFace' - if style == TopStudStyle.OPEN: + add_circle_to_sketch(top_studs_outside_pad_sketch, DIMS_STUD_OUTER_RADIUS, initial_width_offset, + initial_depth_offset, style == TopStudStyle.OPEN) - add_outer_circle_and_inner_circle_with_flats_to_sketch(top_studs_outside_pad_sketch, DIMS_STUD_OUTER_RADIUS, - DIMS_STUD_INNER_RADIUS, DIMS_STUD_FLAT_THICKNESS, - True, initial_width_offset, initial_depth_offset) - else: - add_circle_to_sketch(top_studs_outside_pad_sketch, DIMS_STUD_OUTER_RADIUS, initial_width_offset, - initial_depth_offset) + self.doc.recompute() # create array if needed if self.width_count > 1 or self.depth_count > 1: geometry_indices = [range(0, len(top_studs_outside_pad_sketch.Geometry) - 1)] - if self.width_count == 1 and self.depth_count > 1: - top_studs_outside_pad_sketch.addRectangularArray(geometry_indices, - Vector(0, DIMS_STUD_SPACING, 0), False, - self.depth_count, self.width_count, True) - elif self.width_count > 1 and self.depth_count == 1: + if self.width_count > 1 and self.depth_count == 1: top_studs_outside_pad_sketch.addRectangularArray(geometry_indices, Vector(DIMS_STUD_SPACING, 0, 0), False, self.width_count, self.depth_count, True) @@ -57,6 +49,7 @@ def _render_top_studs_outside(self, initial_width_offset, initial_depth_offset, top_studs_outside_pad_sketch.addRectangularArray(geometry_indices, Vector(0, DIMS_STUD_SPACING, 0), False, self.depth_count, self.width_count, True) + self.doc.recompute() top_studs_outside_pad = self.brick.newObject("PartDesign::Pad", "top_studs_outside_pad") top_studs_outside_pad.Type = PAD_TYPE_DIMENSION @@ -65,43 +58,78 @@ def _render_top_studs_outside(self, initial_width_offset, initial_depth_offset, self.doc.recompute() + top_studs_outside_pad_sketch.ViewObject.Visibility = False + # determine the stud outer edges - # if style == TopStudStyle.OPEN: - # edge_names = get_arc_edge_names(self.top_datum_plane, True, DIMS_STUD_HEIGHT, top_studs_outside_pad, - # DIMS_STUD_OUTER_RADIUS) - # else: - # edge_names = get_circle_edge_names(self.top_datum_plane, True, DIMS_STUD_HEIGHT, top_studs_outside_pad, - # DIMS_STUD_OUTER_RADIUS) - # - # # top studs outer edge fillet - # top_stud_outer_fillets = self.brick.newObject("PartDesign::Fillet", "top_stud_outer_fillets") - # top_stud_outer_fillets.Radius = DIMS_STUD_FILLET - # top_stud_outer_fillets.Base = (top_studs_outside_pad, edge_names) - # - # self.doc.recompute() - # top_studs_outside_pad_sketch.ViewObject.Visibility = False + if style == TopStudStyle.OPEN: + edge_names = get_arc_edge_names(self.top_datum_plane, True, DIMS_STUD_HEIGHT, top_studs_outside_pad, + DIMS_STUD_OUTER_RADIUS) + else: + edge_names = get_circle_edge_names(self.top_datum_plane, True, DIMS_STUD_HEIGHT, top_studs_outside_pad, + DIMS_STUD_OUTER_RADIUS) + if len(edge_names) > 0: + # top studs outer edge fillet + top_stud_outer_fillets = self.brick.newObject("PartDesign::Fillet", "top_stud_outer_fillets") + top_stud_outer_fillets.Radius = DIMS_STUD_FILLET + top_stud_outer_fillets.Base = (top_studs_outside_pad, edge_names) + + self.doc.recompute() + + # top studs outside pocket + if style == TopStudStyle.OPEN: + + top_studs_outside_pocket_sketch = self.brick.newObject("Sketcher::SketchObject", + "top_studs_outside_pocket_sketch") + top_studs_outside_pocket_sketch.Support = (self.top_datum_plane, '') + top_studs_outside_pocket_sketch.MapMode = 'FlatFace' + + add_inner_circle_with_flats_to_sketch(top_studs_outside_pocket_sketch, DIMS_STUD_OUTER_RADIUS, + DIMS_STUD_INNER_RADIUS, DIMS_STUD_FLAT_THICKNESS, + initial_width_offset, initial_depth_offset) + self.doc.recompute() + + # create array if needed + if self.width_count > 1 or self.depth_count > 1: + geometry_indices = [range(0, len(top_studs_outside_pocket_sketch.Geometry) - 1)] + if self.width_count > 1 and self.depth_count == 1: + top_studs_outside_pocket_sketch.addRectangularArray(geometry_indices, + Vector(DIMS_STUD_SPACING, 0, 0), False, + self.width_count, self.depth_count, True) + else: + top_studs_outside_pocket_sketch.addRectangularArray(geometry_indices, + Vector(0, DIMS_STUD_SPACING, 0), False, + self.depth_count, self.width_count, True) + self.doc.recompute() + + top_studs_outside_pocket = self.brick.newObject("PartDesign::Pocket", "top_studs_outside_pocket") + top_studs_outside_pocket.Type = PAD_TYPE_DIMENSION + top_studs_outside_pocket.Profile = top_studs_outside_pocket_sketch + top_studs_outside_pocket.Length = DIMS_STUD_HEIGHT + top_studs_outside_pocket.Reversed = True + + self.doc.recompute() + + top_studs_outside_pocket_sketch.ViewObject.Visibility = False def _render_top_studs_inside(self, initial_width_offset, initial_depth_offset): Console.PrintMessage("render_top_studs_inside({0},{1})\n".format(initial_width_offset, initial_depth_offset)) # top studs inside pocket - top_studs_inside_pocket_sketch = self.brick\ + top_studs_inside_pocket_sketch = self.brick \ .newObject("Sketcher::SketchObject", "top_studs_inside_pocket_sketch") top_studs_inside_pocket_sketch.Support = (self.top_inside_datum_plane, '') top_studs_inside_pocket_sketch.MapMode = 'FlatFace' add_circle_to_sketch(top_studs_inside_pocket_sketch, DIMS_STUD_INSIDE_HOLE_RADIUS, - initial_width_offset, initial_depth_offset) + initial_width_offset, initial_depth_offset, False) + + self.doc.recompute() # create array if needed if self.width > 1 or self.depth > 1: geometry_indices = [range(0, len(top_studs_inside_pocket_sketch.Geometry) - 1)] - if self.width == 1 and self.depth > 1: - top_studs_inside_pocket_sketch.addRectangularArray(geometry_indices, - Vector(0, DIMS_STUD_SPACING, 0), False, - self.depth, self.width, True) - elif self.width > 1 and self.depth == 1: + if self.width > 1 and self.depth == 1: top_studs_inside_pocket_sketch.addRectangularArray(geometry_indices, Vector(DIMS_STUD_SPACING, 0, 0), False, self.width, self.depth, True) @@ -109,6 +137,7 @@ def _render_top_studs_inside(self, initial_width_offset, initial_depth_offset): top_studs_inside_pocket_sketch.addRectangularArray(geometry_indices, Vector(0, DIMS_STUD_SPACING, 0), False, self.depth, self.width, True) + self.doc.recompute() top_studs_inside_pocket = self.brick.newObject("PartDesign::Pocket", "top_studs_inside_pocket") top_studs_inside_pocket.Type = POCKET_TYPE_DIMENSION @@ -117,6 +146,7 @@ def _render_top_studs_inside(self, initial_width_offset, initial_depth_offset): top_studs_inside_pocket.Length = DIMS_STUD_INSIDE_HOLE_TOP_OFFSET self.doc.recompute() + top_studs_inside_pocket_sketch.ViewObject.Visibility = False def render(self, context):