From 717c7549ba4655a6a48f3c79c55c2f14cd492fc1 Mon Sep 17 00:00:00 2001 From: vectronic Date: Sun, 26 Apr 2020 00:08:54 +0100 Subject: [PATCH 1/6] fix: pocket length --- Legify/TopStuds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Legify/TopStuds.py b/Legify/TopStuds.py index 687460b..ab2746c 100644 --- a/Legify/TopStuds.py +++ b/Legify/TopStuds.py @@ -111,7 +111,7 @@ def _render_top_studs_inside(self, initial_width_offset, initial_depth_offset): top_studs_inside_pocket.Type = POCKET_TYPE_DIMENSION top_studs_inside_pocket.Profile = top_studs_inside_pocket_sketch top_studs_inside_pocket.Reversed = True - top_studs_inside_pocket.Length = DIMS_TOP_THICKNESS + DIMS_STUD_INSIDE_HOLE_TOP_OFFSET + top_studs_inside_pocket.Length = DIMS_STUD_INSIDE_HOLE_TOP_OFFSET self.doc.recompute() top_studs_inside_pocket_sketch.ViewObject.Visibility = False From c6d5f2310f6961f68f16a62784e7dd4cac23c1eb Mon Sep 17 00:00:00 2001 From: vectronic Date: Sun, 26 Apr 2020 00:09:37 +0100 Subject: [PATCH 2/6] fix: holes padding length --- Legify/Holes.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Legify/Holes.py b/Legify/Holes.py index e0b6518..bf5ab90 100644 --- a/Legify/Holes.py +++ b/Legify/Holes.py @@ -20,6 +20,8 @@ def __init__(self): self.offset = None self.front_datum_plane = None + self.front_inside_datum_plane = None + self.back_inside_datum_plane = None self.depth_mirror_datum_plane = None self.top_inside_datum_plane = None @@ -85,9 +87,8 @@ def _render_holes(self): # holes pad with cross-section meeting inside of body holes_pad_sketch = self.brick.newObject("Sketcher::SketchObject", "holes_pad_sketch") - holes_pad_sketch.Support = (self.front_datum_plane, '') + holes_pad_sketch.Support = (self.front_inside_datum_plane, '') holes_pad_sketch.MapMode = 'FlatFace' - holes_pad_sketch.AttachmentOffset = Placement(Vector(0, 0, -1 * DIMS_RIBBED_SIDE_THICKNESS), Rotation(0, 0, 0)) geometries = [] constraints = [] @@ -103,7 +104,8 @@ def _render_holes(self): holes_pad_sketch.addConstraint(constraints) holes_pad = self.brick.newObject("PartDesign::Pad", "holes_pad") - holes_pad.Type = PAD_TYPE_TO_LAST + holes_pad.Type = PAD_TYPE_UP_TO_FACE + holes_pad.UpToFace = (self.back_inside_datum_plane, [""]) holes_pad.Profile = holes_pad_sketch holes_pad.Reversed = True @@ -199,6 +201,8 @@ def render(self, context): self.offset = context.holes_offset self.front_datum_plane = context.front_datum_plane + self.front_inside_datum_plane = context.front_inside_datum_plane + self.back_inside_datum_plane = context.back_inside_datum_plane self.depth_mirror_datum_plane = context.depth_mirror_datum_plane self.top_inside_datum_plane = context.top_inside_datum_plane From 8ea1469ae102362553e1bc1148ea185e835fcf8a Mon Sep 17 00:00:00 2001 From: vectronic Date: Sun, 26 Apr 2020 00:09:58 +0100 Subject: [PATCH 3/6] fix: tweaks to dimensions based on assembly evaluation --- Legify/Common.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Legify/Common.py b/Legify/Common.py index 008f7e9..e9793fc 100644 --- a/Legify/Common.py +++ b/Legify/Common.py @@ -22,7 +22,7 @@ def _enum(*args): # Brick Dimensions DIMS_STUD_SPACING_INNER = 8 -DIMS_HALF_STUD_SPACING_OUTER = 3.9 +DIMS_HALF_STUD_SPACING_OUTER = 4 DIMS_PLATE_HEIGHT = 3.2 DIMS_EDGE_FILLET = 0.1 @@ -35,7 +35,7 @@ def _enum(*args): DIMS_SIDE_RIB_WIDTH = 0.65 DIMS_SIDE_RIB_DEPTH = 0.3 -DIMS_STUD_OUTER_RADIUS = 2.5 +DIMS_STUD_OUTER_RADIUS = 2.475 DIMS_STUD_INNER_RADIUS = 1.65 DIMS_STUD_FLAT_THICKNESS = 0.9 DIMS_STUD_HEIGHT = 1.8 @@ -48,7 +48,7 @@ def _enum(*args): DIMS_STICK_RIB_BOTTOM_OFFSET = 2.15 DIMS_STICK_AND_TUBE_BOTTOM_INSET = 0.15 -DIMS_TUBE_OUTER_RADIUS = 4 * math.sqrt(2) - 2.4 +DIMS_TUBE_OUTER_RADIUS = 3.25 DIMS_TUBE_INNER_RADIUS = 2.5 DIMS_TUBE_FLAT_THICKNESS = 0.9 DIMS_TUBE_RIB_THICKNESS = 0.8 From 0a02b005a0df4d609d7c4fc530beee9fea1c521d Mon Sep 17 00:00:00 2001 From: vectronic Date: Sun, 3 May 2020 00:11:22 +0100 Subject: [PATCH 4/6] refactor: simplify body tube geometry by coalescing tube pad and pocket into single pad --- Legify/Body.py | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/Legify/Body.py b/Legify/Body.py index ecf2736..cbe8a59 100644 --- a/Legify/Body.py +++ b/Legify/Body.py @@ -543,9 +543,10 @@ def _render_tubes(self): tubes_pad_sketch.Placement = Placement(Vector(0, 0, DIMS_STICK_AND_TUBE_BOTTOM_INSET), Rotation(Vector(0, 0, 1), 0)) - # Outer circle - add_circle_to_sketch(tubes_pad_sketch, DIMS_TUBE_OUTER_RADIUS, 0.5 * DIMS_STUD_SPACING_INNER, - 0.5 * DIMS_STUD_SPACING_INNER) + add_inner_circle_with_flats_to_sketch(tubes_pad_sketch, DIMS_TUBE_OUTER_RADIUS, + DIMS_TUBE_INNER_RADIUS, DIMS_STUD_FLAT_THICKNESS, False, + 0.5 * DIMS_STUD_SPACING_INNER, + 0.5 * DIMS_STUD_SPACING_INNER) # create array if needed if self.width > 2 or self.depth > 2: @@ -568,36 +569,6 @@ def _render_tubes(self): self.doc.recompute() tubes_pad_sketch.ViewObject.Visibility = False - # tubes pocket - - tubes_pocket_sketch = self.brick.newObject("Sketcher::SketchObject", "tubes_pocket_sketch") - tubes_pocket_sketch.Support = (self.top_inside_datum_plane, '') - tubes_pocket_sketch.MapMode = 'FlatFace' - - add_inner_circle_with_flats_to_sketch(tubes_pocket_sketch, DIMS_TUBE_OUTER_RADIUS, DIMS_TUBE_INNER_RADIUS, - DIMS_STUD_FLAT_THICKNESS, True, 0.5 * DIMS_STUD_SPACING_INNER, - 0.5 * DIMS_STUD_SPACING_INNER) - - # 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_INNER, 0), False, - self.depth - 1, self.width - 1, True) - elif self.width > 2 and self.depth == 2: - tubes_pocket_sketch.addRectangularArray(geometry_indices, Vector(DIMS_STUD_SPACING_INNER, 0, 0), False, - self.width - 1, self.depth - 1, True) - else: - tubes_pocket_sketch.addRectangularArray(geometry_indices, Vector(0, DIMS_STUD_SPACING_INNER, 0), False, - self.depth - 1, self.width - 1, True) - - tubes_pocket = self.brick.newObject("PartDesign::Pocket", "tubes_pocket") - tubes_pocket.Type = POCKET_TYPE_THROUGH_ALL - tubes_pocket.Profile = tubes_pocket_sketch - - self.doc.recompute() - tubes_pocket_sketch.ViewObject.Visibility = False - def _render_stick_ribs(self): Console.PrintMessage("_render_stick_ribs()\n") From fab68ee1b9755cf2b6f8b81d92509988a9bf9a6d Mon Sep 17 00:00:00 2001 From: vectronic Date: Mon, 25 May 2020 15:44:02 +0100 Subject: [PATCH 5/6] fix: improvements based on using in techdraw --- Legify/Body.py | 110 ++++++++++++------- Legify/Brick.py | 22 ++-- Legify/Common.py | 250 ++++++++++++++++++++++++++++++-------------- Legify/Holes.py | 14 +-- Legify/SideStuds.py | 36 +++---- Legify/TopStuds.py | 47 +++++---- 6 files changed, 301 insertions(+), 178 deletions(-) diff --git a/Legify/Body.py b/Legify/Body.py index cbe8a59..bf4af85 100644 --- a/Legify/Body.py +++ b/Legify/Body.py @@ -150,7 +150,7 @@ def _add_rib_sketch(geometries, constraints, tube_index, rib_thickness, bottom_o segment_count = len(geometries) # offset from origin for this rib - rib_x_offset = (tube_index - 1) * DIMS_STUD_SPACING_INNER + (DIMS_STUD_SPACING_INNER - rib_thickness) / 2 + rib_x_offset = (tube_index - 1) * DIMS_STUD_SPACING + (DIMS_STUD_SPACING - rib_thickness) / 2 fillet_radius = rib_thickness / 2 @@ -233,16 +233,16 @@ def _render_body_pad_and_fillets(self): # Half stud offsets from origin Sketcher.Constraint("DistanceX", 0, SKETCH_GEOMETRY_VERTEX_START_INDEX, SKETCH_GEOMETRY_ORIGIN_INDEX, - SKETCH_GEOMETRY_VERTEX_START_INDEX, DIMS_HALF_STUD_SPACING_OUTER), + SKETCH_GEOMETRY_VERTEX_START_INDEX, DIMS_STUD_SPACING / 2), Sketcher.Constraint("DistanceY", 0, SKETCH_GEOMETRY_VERTEX_START_INDEX, SKETCH_GEOMETRY_ORIGIN_INDEX, - SKETCH_GEOMETRY_VERTEX_START_INDEX, DIMS_HALF_STUD_SPACING_OUTER), + SKETCH_GEOMETRY_VERTEX_START_INDEX, DIMS_STUD_SPACING / 2), # Width Sketcher.Constraint("DistanceX", 0, SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, SKETCH_GEOMETRY_VERTEX_END_INDEX, - (self.width - 1) * DIMS_STUD_SPACING_INNER + (2 * DIMS_HALF_STUD_SPACING_OUTER)), + (self.width - 1) * DIMS_STUD_SPACING + DIMS_STUD_SPACING), # Depth Sketcher.Constraint("DistanceY", 1, SKETCH_GEOMETRY_VERTEX_START_INDEX, 1, SKETCH_GEOMETRY_VERTEX_END_INDEX, - (self.depth - 1) * DIMS_STUD_SPACING_INNER + (2 * DIMS_HALF_STUD_SPACING_OUTER)) + (self.depth - 1) * DIMS_STUD_SPACING + DIMS_STUD_SPACING) ]) body_pad = self.brick.newObject("PartDesign::Pad", "body_pad") @@ -284,7 +284,7 @@ def _render_body_pocket(self): # complex rectangle with ribs # First horizontal => 1st half stud self._add_horizontal_sketch_segment(geometries, constraints, - DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS + (DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS - (DIMS_SIDE_RIB_WIDTH / 2), xy_plane_top_left_vector(), xy_plane_top_right_vector(), False) @@ -292,7 +292,7 @@ def _render_body_pocket(self): # => N-1 studs for i in range(0, self.width - 1): self._add_horizontal_sketch_segment_with_rib(geometries, constraints, - DIMS_STUD_SPACING_INNER, + DIMS_STUD_SPACING, xy_plane_top_left_vector(), xy_plane_top_right_vector(), xy_plane_top_right_vector(), xy_plane_bottom_right_vector(), @@ -300,7 +300,7 @@ def _render_body_pocket(self): # => Last half stud self._add_horizontal_sketch_segment_with_rib(geometries, constraints, - DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS + (DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS + (DIMS_SIDE_RIB_WIDTH / 2), xy_plane_top_left_vector(), xy_plane_top_right_vector(), xy_plane_top_right_vector(), xy_plane_bottom_right_vector(), @@ -308,7 +308,7 @@ def _render_body_pocket(self): # First vertical => 1st half stud self._add_vertical_sketch_segment(geometries, constraints, - DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS + (DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS - (DIMS_SIDE_RIB_WIDTH / 2), xy_plane_top_right_vector(), xy_plane_bottom_right_vector(), False) @@ -316,7 +316,7 @@ def _render_body_pocket(self): # => N-1 studs for i in range(0, self.depth - 1): self._add_vertical_sketch_segment_with_rib(geometries, constraints, - DIMS_STUD_SPACING_INNER, + DIMS_STUD_SPACING, xy_plane_top_right_vector(), xy_plane_bottom_right_vector(), xy_plane_bottom_right_vector(), xy_plane_bottom_left_vector(), @@ -324,7 +324,7 @@ def _render_body_pocket(self): # => Last half stud self._add_vertical_sketch_segment_with_rib(geometries, constraints, - DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS + (DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS + (DIMS_SIDE_RIB_WIDTH / 2), xy_plane_top_right_vector(), xy_plane_bottom_right_vector(), xy_plane_bottom_right_vector(), xy_plane_bottom_left_vector(), @@ -332,7 +332,7 @@ def _render_body_pocket(self): # Second horizontal => 1st half stud self._add_horizontal_sketch_segment(geometries, constraints, - DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS + (DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS - (DIMS_SIDE_RIB_WIDTH / 2), xy_plane_top_left_vector(), xy_plane_top_right_vector(), True) @@ -340,7 +340,7 @@ def _render_body_pocket(self): # => N-1 studs for i in range(0, self.width - 1): self._add_horizontal_sketch_segment_with_rib(geometries, constraints, - DIMS_STUD_SPACING_INNER, + DIMS_STUD_SPACING, xy_plane_top_left_vector(), xy_plane_top_right_vector(), xy_plane_top_right_vector(), xy_plane_bottom_right_vector(), @@ -348,7 +348,7 @@ def _render_body_pocket(self): # => Last half stud self._add_horizontal_sketch_segment_with_rib(geometries, constraints, - DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS + (DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS + (DIMS_SIDE_RIB_WIDTH / 2), xy_plane_top_left_vector(), xy_plane_top_right_vector(), xy_plane_top_right_vector(), xy_plane_bottom_right_vector(), @@ -356,7 +356,7 @@ def _render_body_pocket(self): # Second vertical => 1st half stud self._add_vertical_sketch_segment(geometries, constraints, - DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS + (DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS - (DIMS_SIDE_RIB_WIDTH / 2), xy_plane_top_right_vector(), xy_plane_bottom_right_vector(), True) @@ -364,7 +364,7 @@ def _render_body_pocket(self): # => N-1 studs for i in range(0, self.depth - 1): self._add_vertical_sketch_segment_with_rib(geometries, constraints, - DIMS_STUD_SPACING_INNER, + DIMS_STUD_SPACING, xy_plane_top_right_vector(), xy_plane_bottom_right_vector(), xy_plane_bottom_right_vector(), xy_plane_bottom_left_vector(), @@ -372,7 +372,7 @@ def _render_body_pocket(self): # => Last half stud self._add_vertical_sketch_segment_with_rib(geometries, constraints, - DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS + (DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS + (DIMS_SIDE_RIB_WIDTH / 2), xy_plane_top_right_vector(), xy_plane_bottom_right_vector(), xy_plane_bottom_right_vector(), xy_plane_bottom_left_vector(), @@ -381,10 +381,10 @@ def _render_body_pocket(self): # Half stud offsets from origin (-1, 1 chooses the origin point) constraints.append(Sketcher.Constraint("DistanceX", 0, SKETCH_GEOMETRY_VERTEX_START_INDEX, -1, SKETCH_GEOMETRY_VERTEX_START_INDEX, - DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS)) + (DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS)) constraints.append(Sketcher.Constraint("DistanceY", 0, SKETCH_GEOMETRY_VERTEX_START_INDEX, -1, SKETCH_GEOMETRY_VERTEX_START_INDEX, - DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS)) + (DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS)) else: # simple rectangle @@ -413,23 +413,23 @@ def _render_body_pocket(self): # Width constraints.append(Sketcher.Constraint("DistanceX", 0, SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, SKETCH_GEOMETRY_VERTEX_END_INDEX, - (self.width - 1) * DIMS_STUD_SPACING_INNER - + (2 * DIMS_HALF_STUD_SPACING_OUTER) + (self.width - 1) * DIMS_STUD_SPACING + + DIMS_STUD_SPACING - (2 * DIMS_FLAT_SIDE_THICKNESS))) # Depth constraints.append(Sketcher.Constraint("DistanceY", 1, SKETCH_GEOMETRY_VERTEX_START_INDEX, 1, SKETCH_GEOMETRY_VERTEX_END_INDEX, - (self.depth - 1) * DIMS_STUD_SPACING_INNER - + (2 * DIMS_HALF_STUD_SPACING_OUTER) + (self.depth - 1) * DIMS_STUD_SPACING + + DIMS_STUD_SPACING - (2 * DIMS_FLAT_SIDE_THICKNESS))) # Half stud offsets from origin constraints.append(Sketcher.Constraint("DistanceX", 0, SKETCH_GEOMETRY_VERTEX_START_INDEX, SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, - DIMS_HALF_STUD_SPACING_OUTER - DIMS_FLAT_SIDE_THICKNESS)) + (DIMS_STUD_SPACING / 2) - DIMS_FLAT_SIDE_THICKNESS)) constraints.append(Sketcher.Constraint("DistanceY", 0, SKETCH_GEOMETRY_VERTEX_START_INDEX, SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, - DIMS_HALF_STUD_SPACING_OUTER - DIMS_FLAT_SIDE_THICKNESS)) + (DIMS_STUD_SPACING / 2) - DIMS_FLAT_SIDE_THICKNESS)) body_pocket_sketch.addGeometry(geometries, False) body_pocket_sketch.addConstraint(constraints) @@ -543,22 +543,21 @@ def _render_tubes(self): tubes_pad_sketch.Placement = Placement(Vector(0, 0, DIMS_STICK_AND_TUBE_BOTTOM_INSET), Rotation(Vector(0, 0, 1), 0)) - add_inner_circle_with_flats_to_sketch(tubes_pad_sketch, DIMS_TUBE_OUTER_RADIUS, - DIMS_TUBE_INNER_RADIUS, DIMS_STUD_FLAT_THICKNESS, False, - 0.5 * DIMS_STUD_SPACING_INNER, - 0.5 * DIMS_STUD_SPACING_INNER) + # Outer circle + add_circle_to_sketch(tubes_pad_sketch, DIMS_TUBE_OUTER_RADIUS, 0.5 * DIMS_STUD_SPACING, + 0.5 * DIMS_STUD_SPACING) # 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_INNER, 0), False, + 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: - tubes_pad_sketch.addRectangularArray(geometry_indices, Vector(DIMS_STUD_SPACING_INNER, 0, 0), False, + 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_INNER, 0), False, + tubes_pad_sketch.addRectangularArray(geometry_indices, Vector(0, DIMS_STUD_SPACING, 0), False, self.depth - 1, self.width - 1, True) tubes_pad = self.brick.newObject("PartDesign::Pad", "tubes_pad") @@ -569,6 +568,37 @@ def _render_tubes(self): self.doc.recompute() tubes_pad_sketch.ViewObject.Visibility = False + # tubes pocket + + tubes_pocket_sketch = self.brick.newObject("Sketcher::SketchObject", "tubes_pocket_sketch") + 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) + + # 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: + 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) + + tubes_pocket = self.brick.newObject("PartDesign::Pocket", "tubes_pocket") + tubes_pocket.Type = POCKET_TYPE_THROUGH_ALL + tubes_pocket.Profile = tubes_pocket_sketch + + self.doc.recompute() + tubes_pocket_sketch.ViewObject.Visibility = False + def _render_stick_ribs(self): Console.PrintMessage("_render_stick_ribs()\n") @@ -652,7 +682,7 @@ def _render_sticks(self): if self.width > 1: constraints.append(Sketcher.Constraint("DistanceX", SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, - SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, 0.5 * DIMS_STUD_SPACING_INNER)) + SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, 0.5 * DIMS_STUD_SPACING)) constraints.append(Sketcher.Constraint("DistanceY", SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, 0)) @@ -662,16 +692,16 @@ def _render_sticks(self): SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, 0)) constraints.append(Sketcher.Constraint("DistanceY", SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, - SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, 0.5 * DIMS_STUD_SPACING_INNER)) + SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, 0.5 * DIMS_STUD_SPACING)) sticks_pad_sketch.addGeometry(geometries, False) sticks_pad_sketch.addConstraint(constraints) if self.width > 1: - sticks_pad_sketch.addRectangularArray([0], Vector(DIMS_STUD_SPACING_INNER, 0, 0), False, + 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_INNER, 0), False, + sticks_pad_sketch.addRectangularArray([0], Vector(0, DIMS_STUD_SPACING, 0), False, self.depth - 1, 1, True) sticks_pad = self.brick.newObject("PartDesign::Pad", "sticks_pad") @@ -699,7 +729,7 @@ def _render_sticks(self): constraints.append(Sketcher.Constraint("DistanceX", SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, - 0.5 * DIMS_STUD_SPACING_INNER)) + 0.5 * DIMS_STUD_SPACING)) constraints.append(Sketcher.Constraint("DistanceY", SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, 0)) @@ -710,16 +740,16 @@ def _render_sticks(self): constraints.append(Sketcher.Constraint("DistanceY", SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, - 0.5 * DIMS_STUD_SPACING_INNER)) + 0.5 * DIMS_STUD_SPACING)) sticks_pocket_sketch.addGeometry(geometries, False) sticks_pocket_sketch.addConstraint(constraints) if self.width > 1: - sticks_pocket_sketch.addRectangularArray([0], Vector(DIMS_STUD_SPACING_INNER, 0, 0), False, + 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_INNER, 0), False, + sticks_pocket_sketch.addRectangularArray([0], Vector(0, DIMS_STUD_SPACING, 0), False, self.depth - 1, 1, True) sticks_pocket = self.brick.newObject("PartDesign::Pocket", "sticks_pocket") diff --git a/Legify/Brick.py b/Legify/Brick.py index 4cd2c5d..6fc0c22 100644 --- a/Legify/Brick.py +++ b/Legify/Brick.py @@ -321,7 +321,7 @@ def _create_datum_planes(self, context): front_datum_plane.MapReversed = False front_datum_plane.Support = [(context.brick.Origin.OriginFeatures[ORIGIN_XZ_PLANE_INDEX], '')] front_datum_plane.MapMode = 'FlatFace' - front_datum_plane.AttachmentOffset = Placement(Vector(0, 0, DIMS_HALF_STUD_SPACING_OUTER), Rotation(0, 0, 0)) + front_datum_plane.AttachmentOffset = Placement(Vector(0, 0, DIMS_STUD_SPACING / 2), Rotation(0, 0, 0)) front_datum_plane.ViewObject.Visibility = False context.front_datum_plane = front_datum_plane @@ -331,7 +331,7 @@ def _create_datum_planes(self, context): back_datum_plane.Support = [(context.brick.Origin.OriginFeatures[ORIGIN_XZ_PLANE_INDEX], '')] back_datum_plane.MapMode = 'FlatFace' back_datum_plane.AttachmentOffset = Placement( - Vector(0, 0, -1 * (DIMS_HALF_STUD_SPACING_OUTER + (DIMS_STUD_SPACING_INNER * (context.depth - 1)))), + Vector(0, 0, -1 * ((DIMS_STUD_SPACING / 2) + (DIMS_STUD_SPACING * (context.depth - 1)))), Rotation(0, 0, 0)) back_datum_plane.ViewObject.Visibility = False context.back_datum_plane = back_datum_plane @@ -341,7 +341,7 @@ def _create_datum_planes(self, context): left_datum_plane.MapReversed = False left_datum_plane.Support = [(context.brick.Origin.OriginFeatures[ORIGIN_YZ_PLANE_INDEX], '')] left_datum_plane.MapMode = 'FlatFace' - left_datum_plane.AttachmentOffset = Placement(Vector(0, 0, -1 * DIMS_HALF_STUD_SPACING_OUTER), + left_datum_plane.AttachmentOffset = Placement(Vector(0, 0, -1 * DIMS_STUD_SPACING / 2), Rotation(0, 0, 0)) left_datum_plane.ViewObject.Visibility = False context.left_datum_plane = left_datum_plane @@ -352,7 +352,7 @@ def _create_datum_planes(self, context): right_datum_plane.Support = [(context.brick.Origin.OriginFeatures[ORIGIN_YZ_PLANE_INDEX], '')] right_datum_plane.MapMode = 'FlatFace' right_datum_plane.AttachmentOffset = Placement( - Vector(0, 0, DIMS_HALF_STUD_SPACING_OUTER + (DIMS_STUD_SPACING_INNER * (context.width - 1))), + Vector(0, 0, (DIMS_STUD_SPACING / 2) + (DIMS_STUD_SPACING * (context.width - 1))), Rotation(0, 0, 0)) right_datum_plane.ViewObject.Visibility = False context.right_datum_plane = right_datum_plane @@ -373,7 +373,7 @@ def _create_datum_planes(self, context): front_inside_datum_plane.Support = [(context.brick.Origin.OriginFeatures[ORIGIN_XZ_PLANE_INDEX], '')] front_inside_datum_plane.MapMode = 'FlatFace' front_inside_datum_plane.AttachmentOffset = Placement( - Vector(0, 0, DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS), Rotation(0, 0, 0)) + Vector(0, 0, (DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS), Rotation(0, 0, 0)) front_inside_datum_plane.ViewObject.Visibility = False context.front_inside_datum_plane = front_inside_datum_plane @@ -383,8 +383,8 @@ def _create_datum_planes(self, context): back_inside_datum_plane.Support = [(context.brick.Origin.OriginFeatures[ORIGIN_XZ_PLANE_INDEX], '')] back_inside_datum_plane.MapMode = 'FlatFace' back_inside_datum_plane.AttachmentOffset = Placement( - Vector(0, 0, -1 * ((self.depth - 1) * DIMS_STUD_SPACING_INNER + - (DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS))), Rotation(0, 0, 0)) + Vector(0, 0, -1 * ((self.depth - 1) * DIMS_STUD_SPACING + + ((DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS))), Rotation(0, 0, 0)) back_inside_datum_plane.ViewObject.Visibility = False context.back_inside_datum_plane = back_inside_datum_plane @@ -394,7 +394,7 @@ def _create_datum_planes(self, context): left_inside_datum_plane.Support = [(context.brick.Origin.OriginFeatures[ORIGIN_YZ_PLANE_INDEX], '')] left_inside_datum_plane.MapMode = 'FlatFace' left_inside_datum_plane.AttachmentOffset = Placement( - Vector(0, 0, -1 * (DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS)), Rotation(0, 0, 0)) + Vector(0, 0, -1 * ((DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS)), Rotation(0, 0, 0)) left_inside_datum_plane.ViewObject.Visibility = False context.left_inside_datum_plane = left_inside_datum_plane @@ -404,8 +404,8 @@ def _create_datum_planes(self, context): right_inside_datum_plane.Support = [(context.brick.Origin.OriginFeatures[ORIGIN_YZ_PLANE_INDEX], '')] right_inside_datum_plane.MapMode = 'FlatFace' right_inside_datum_plane.AttachmentOffset = Placement( - Vector(0, 0, (self.width - 1) * DIMS_STUD_SPACING_INNER + - (DIMS_HALF_STUD_SPACING_OUTER - DIMS_RIBBED_SIDE_THICKNESS)), Rotation(0, 0, 0)) + Vector(0, 0, (self.width - 1) * DIMS_STUD_SPACING + + ((DIMS_STUD_SPACING / 2) - DIMS_RIBBED_SIDE_THICKNESS)), Rotation(0, 0, 0)) right_inside_datum_plane.ViewObject.Visibility = False context.right_inside_datum_plane = right_inside_datum_plane @@ -415,7 +415,7 @@ def _create_datum_planes(self, context): depth_mirror_datum_plane.Support = [(context.brick.Origin.OriginFeatures[ORIGIN_XZ_PLANE_INDEX], '')] depth_mirror_datum_plane.MapMode = 'FlatFace' depth_mirror_datum_plane.AttachmentOffset = Placement( - Vector(0, 0, -1 * ((self.depth - 1) * DIMS_STUD_SPACING_INNER / 2)), Rotation(0, 0, 0)) + Vector(0, 0, -1 * ((self.depth - 1) * DIMS_STUD_SPACING / 2)), Rotation(0, 0, 0)) depth_mirror_datum_plane.ViewObject.Visibility = False context.depth_mirror_datum_plane = depth_mirror_datum_plane diff --git a/Legify/Common.py b/Legify/Common.py index e9793fc..34b684e 100644 --- a/Legify/Common.py +++ b/Legify/Common.py @@ -21,8 +21,7 @@ def _enum(*args): # Brick Dimensions -DIMS_STUD_SPACING_INNER = 8 -DIMS_HALF_STUD_SPACING_OUTER = 4 +DIMS_STUD_SPACING = 8 DIMS_PLATE_HEIGHT = 3.2 DIMS_EDGE_FILLET = 0.1 @@ -160,58 +159,42 @@ def add_circle_to_sketch(sketch, radius, x, y): sketch.addConstraint(constraints) -def add_inner_circle_with_flats_to_sketch(sketch, outer_construction_radius, radius, flat_thickness, - outer_circle_is_construction, x_offset, y_offset): - Console.PrintMessage("add_inner_circle_with_flats_to_sketch({0},{1},{2},{3},{4},{5})\n" - .format(outer_construction_radius, radius, flat_thickness, outer_circle_is_construction, +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)) geometries = [] constraints = [] - # Outer circle for construction - geometries.append(Part.Circle()) - constraints.append(Sketcher.Constraint("Radius", 0, outer_construction_radius)) + # 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_CENTRE_INDEX, x_offset)) + SKETCH_GEOMETRY_VERTEX_END_INDEX, x_offset)) constraints.append(Sketcher.Constraint("DistanceY", SKETCH_GEOMETRY_ORIGIN_INDEX, SKETCH_GEOMETRY_VERTEX_START_INDEX, 0, - SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, y_offset)) - - # Tangent construction line - geometries.append(Part.LineSegment(xy_plane_top_left_vector(), xy_plane_bottom_right_vector())) - constraints.append(Sketcher.Constraint('Angle', 1, -45 * math.pi / 180)) - constraints.append(Sketcher.Constraint('Tangent', 1, 0)) - constraints.append(Sketcher.Constraint('PointOnObject', 1, SKETCH_GEOMETRY_VERTEX_END_INDEX, 0)) - constraints.append(Sketcher.Constraint("DistanceX", 1, SKETCH_GEOMETRY_VERTEX_START_INDEX, 1, - SKETCH_GEOMETRY_VERTEX_END_INDEX, 1)) + SKETCH_GEOMETRY_VERTEX_END_INDEX, y_offset)) + constraints.append(Sketcher.Constraint("Distance", 0, SKETCH_GEOMETRY_VERTEX_START_INDEX, + 0, SKETCH_GEOMETRY_VERTEX_END_INDEX, outer_radius)) # Four Line Segments - x1 = (DIMS_STUD_SPACING_INNER / 2) - 2 - x2 = (DIMS_STUD_SPACING_INNER / 2) - 1 - x3 = (DIMS_STUD_SPACING_INNER / 2) + 1 - x4 = (DIMS_STUD_SPACING_INNER / 2) + 2 - y1 = (DIMS_STUD_SPACING_INNER / 2) - 2 - y2 = (DIMS_STUD_SPACING_INNER / 2) - 1 - y3 = (DIMS_STUD_SPACING_INNER / 2) + 1 - y4 = (DIMS_STUD_SPACING_INNER / 2) + 2 + x1 = (DIMS_STUD_SPACING / 2) - 2 + x2 = (DIMS_STUD_SPACING / 2) - 1 + x3 = (DIMS_STUD_SPACING / 2) + 1 + x4 = (DIMS_STUD_SPACING / 2) + 2 + y1 = (DIMS_STUD_SPACING / 2) - 2 + y2 = (DIMS_STUD_SPACING / 2) - 1 + y3 = (DIMS_STUD_SPACING / 2) + 1 + y4 = (DIMS_STUD_SPACING / 2) + 2 geometries.append(Part.LineSegment(Vector(x2, y1, 0), Vector(x1, y2, 0))) geometries.append(Part.LineSegment(Vector(x1, y3, 0), Vector(x2, y4, 0))) geometries.append(Part.LineSegment(Vector(x3, y4, 0), Vector(x4, y3, 0))) geometries.append(Part.LineSegment(Vector(x4, y2, 0), Vector(x3, y1, 0))) - constraints.append(Sketcher.Constraint('Equal', 2, 4)) - constraints.append(Sketcher.Constraint('Equal', 3, 5)) - constraints.append(Sketcher.Constraint('Equal', 2, 3)) - constraints.append(Sketcher.Constraint('Parallel', 3, 5)) - constraints.append(Sketcher.Constraint('Parallel', 2, 4)) - constraints.append(Sketcher.Constraint('Perpendicular', 2, 3)) - - # Parallel to tangent line as - constraints.append(Sketcher.Constraint('Parallel', 1, 2)) - # Four Arcs rad1 = 160 * math.pi / 180 rad2 = 200 * math.pi / 180 @@ -222,57 +205,112 @@ def add_inner_circle_with_flats_to_sketch(sketch, outer_construction_radius, rad rad7 = -110 * math.pi / 180 rad8 = -70 * math.pi / 180 - 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)) - geometries.append(Part.ArcOfCircle(Part.Circle(Vector(4, 4, 0), Vector(0, 0, 1), radius), rad5, rad6)) - geometries.append(Part.ArcOfCircle(Part.Circle(Vector(4, 4, 0), Vector(0, 0, 1), radius), rad7, rad8)) + geometries.append(Part.ArcOfCircle(Part.Circle(Vector(4, 4, 0), Vector(0, 0, 1), inner_radius), rad1, rad2)) + geometries.append(Part.ArcOfCircle(Part.Circle(Vector(4, 4, 0), Vector(0, 0, 1), inner_radius), rad3, rad4)) + 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)) + + # Link arcs to segments + constraints.append(Sketcher.Constraint('Coincident', + 1, SKETCH_GEOMETRY_VERTEX_START_INDEX, + 8, SKETCH_GEOMETRY_VERTEX_START_INDEX)) + constraints.append(Sketcher.Constraint('Coincident', + 1, SKETCH_GEOMETRY_VERTEX_END_INDEX, + 5, SKETCH_GEOMETRY_VERTEX_END_INDEX)) + constraints.append(Sketcher.Constraint('Coincident', + 2, SKETCH_GEOMETRY_VERTEX_START_INDEX, + 5, SKETCH_GEOMETRY_VERTEX_START_INDEX)) + constraints.append(Sketcher.Constraint('Coincident', + 2, SKETCH_GEOMETRY_VERTEX_END_INDEX, + 6, SKETCH_GEOMETRY_VERTEX_END_INDEX)) + constraints.append(Sketcher.Constraint('Coincident', + 3, SKETCH_GEOMETRY_VERTEX_START_INDEX, + 6, SKETCH_GEOMETRY_VERTEX_START_INDEX)) + constraints.append(Sketcher.Constraint('Coincident', + 3, SKETCH_GEOMETRY_VERTEX_END_INDEX, + 7, SKETCH_GEOMETRY_VERTEX_END_INDEX)) + constraints.append(Sketcher.Constraint('Coincident', + 4, SKETCH_GEOMETRY_VERTEX_START_INDEX, + 7, SKETCH_GEOMETRY_VERTEX_START_INDEX)) + constraints.append(Sketcher.Constraint('Coincident', + 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', 6, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, 0, - SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', 7, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, 0, - SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', 8, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, 0, - SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', 9, SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX, 0, - SKETCH_GEOMETRY_VERTEX_CENTRE_INDEX)) + 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', 6, radius)) - constraints.append(Sketcher.Constraint('Equal', 6, 7)) - constraints.append(Sketcher.Constraint('Equal', 6, 8)) - constraints.append(Sketcher.Constraint('Equal', 6, 9)) - - # Link arcs to segments - constraints.append(Sketcher.Constraint('Coincident', 2, SKETCH_GEOMETRY_VERTEX_END_INDEX, 6, - SKETCH_GEOMETRY_VERTEX_END_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', 6, SKETCH_GEOMETRY_VERTEX_START_INDEX, 3, - SKETCH_GEOMETRY_VERTEX_START_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', 3, SKETCH_GEOMETRY_VERTEX_END_INDEX, 7, - SKETCH_GEOMETRY_VERTEX_END_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', 7, SKETCH_GEOMETRY_VERTEX_START_INDEX, 4, - SKETCH_GEOMETRY_VERTEX_START_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', 4, SKETCH_GEOMETRY_VERTEX_END_INDEX, 8, - SKETCH_GEOMETRY_VERTEX_END_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', 8, SKETCH_GEOMETRY_VERTEX_START_INDEX, 5, - SKETCH_GEOMETRY_VERTEX_START_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', 5, SKETCH_GEOMETRY_VERTEX_END_INDEX, 9, - SKETCH_GEOMETRY_VERTEX_END_INDEX)) - constraints.append(Sketcher.Constraint('Coincident', 9, SKETCH_GEOMETRY_VERTEX_START_INDEX, 2, - SKETCH_GEOMETRY_VERTEX_START_INDEX)) - - # The critical measurement: distance to tangent construction line - constraints.append(Sketcher.Constraint('Distance', 1, SKETCH_GEOMETRY_VERTEX_END_INDEX, 2, flat_thickness)) + 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) - # Set circle as a construction line if specified - if outer_circle_is_construction: - sketch.toggleConstruction(0) - - # Set tangent line as a construction line - sketch.toggleConstruction(1) + # Set construction lines + sketch.toggleConstruction(0) def get_circle_edge_names(plane, inverted, offset, feature, radius): @@ -325,3 +363,55 @@ def get_circle_edge_names(plane, inverted, offset, feature, radius): if c1.Center == c2.Center and c1.Axis == c2.Axis: edge_names.append("Edge" + repr(i + 1)) return edge_names + + +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)) + + plane_normal = plane.Shape.normalAt(0, 0) + plane_normal = plane_normal if inverted else plane_normal.negative() + + edge_names = [] + potential_edges = [] + + for i in range(0, len(feature.Shape.Faces)): + face = feature.Shape.Faces[i] + + # desired faces are normal to plane + face_normal = face.normalAt(0, 0) + if face_normal.isEqual(plane_normal, 1e-7): + + # desired faces have am arc edge + for j in range(0, len(face.Edges)): + edge = face.Edges[j] + + # 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: + + # 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) + + 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)) + return edge_names diff --git a/Legify/Holes.py b/Legify/Holes.py index bf5ab90..1679435 100644 --- a/Legify/Holes.py +++ b/Legify/Holes.py @@ -82,7 +82,7 @@ def _render_holes(self): Console.PrintMessage("render_holes()\n") hole_count = self.width if self.offset else (self.width - 1) - hole_offset = 0 if self.offset else (DIMS_STUD_SPACING_INNER / 2) + hole_offset = 0 if self.offset else (DIMS_STUD_SPACING / 2) # holes pad with cross-section meeting inside of body @@ -98,7 +98,7 @@ def _render_holes(self): holes_pad_sketch.addExternal(self.top_inside_datum_plane.Label, '') for i in range(0, hole_count): - self._add_technic_surround(geometries, constraints, hole_offset + (i * DIMS_STUD_SPACING_INNER)) + self._add_technic_surround(geometries, constraints, hole_offset + (i * DIMS_STUD_SPACING)) holes_pad_sketch.addGeometry(geometries, False) holes_pad_sketch.addConstraint(constraints) @@ -119,7 +119,7 @@ def _render_holes(self): holes_pocket_sketch.MapMode = 'FlatFace' # TODO: if/else render axle cross-section - # self._add_axle_hole_sketch(geometries, constraints, hole_offset + (i * DIMS_STUD_SPACING_INNER)) + # 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) @@ -127,7 +127,7 @@ def _render_holes(self): if hole_count > 1: geometry_indices = [range(0, len(holes_pocket_sketch.Geometry) - 1)] holes_pocket_sketch.addRectangularArray(geometry_indices, - Vector(DIMS_STUD_SPACING_INNER, 0, 0), False, + Vector(DIMS_STUD_SPACING, 0, 0), False, hole_count, 1, True) holes_pocket = self.brick.newObject("PartDesign::Pocket", "holes_pocket") @@ -153,7 +153,7 @@ def _render_holes(self): if hole_count > 1: geometry_indices = [range(0, len(holes_pocket_sketch.Geometry) - 1)] holes_counterbore_pocket_sketch.addRectangularArray(geometry_indices, - Vector(DIMS_STUD_SPACING_INNER, 0, 0), False, + Vector(DIMS_STUD_SPACING, 0, 0), False, hole_count, 1, True) holes_counterbore_pocket = self.brick.newObject("PartDesign::Pocket", "holes_counterbore_pocket") @@ -178,8 +178,8 @@ def _render_holes(self): edge_names = get_circle_edge_names(self.front_datum_plane, True, 0, holes_counterbore_mirror, DIMS_TECHNIC_HOLE_COUNTERBORE_RADIUS) - edge_names.extend(get_circle_edge_names(self.front_datum_plane, False, (2 * DIMS_HALF_STUD_SPACING_OUTER) - + ((self.depth - 1) * DIMS_STUD_SPACING_INNER), + edge_names.extend(get_circle_edge_names(self.front_datum_plane, False, DIMS_STUD_SPACING + + ((self.depth - 1) * DIMS_STUD_SPACING), holes_counterbore_mirror, DIMS_TECHNIC_HOLE_COUNTERBORE_RADIUS)) hole_counterbore_fillets = self.brick.newObject("PartDesign::Fillet", "hole_counterbore_fillets") diff --git a/Legify/SideStuds.py b/Legify/SideStuds.py index fa65f9c..c08db5d 100644 --- a/Legify/SideStuds.py +++ b/Legify/SideStuds.py @@ -37,15 +37,15 @@ 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_inner_circle_with_flats_to_sketch(side_studs_outside_pad_sketch, DIMS_STUD_OUTER_RADIUS, - DIMS_STUD_INNER_RADIUS, DIMS_STUD_FLAT_THICKNESS, False, - 0, DIMS_SIDE_STUD_CENTRE_HEIGHT) + 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) # create array if needed if count > 1: geometry_indices = [range(0, len(side_studs_outside_pad_sketch.Geometry) - 1)] side_studs_outside_pad_sketch.addRectangularArray(geometry_indices, - Vector(DIMS_STUD_SPACING_INNER, 0, 0), False, + Vector(DIMS_STUD_SPACING, 0, 0), False, count, 1, True) side_studs_outside_pad = self.brick.newObject("PartDesign::Pad", label + "_side_studs_outside_pad") @@ -57,16 +57,16 @@ def _render_side_studs_outside(self, label, plane, count, inverted): self.doc.recompute() # determine the stud outer edges - edge_names = get_circle_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) + # + # # 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 def _render_side_studs_inside(self, label, plane, count, inverted): Console.PrintMessage("render_side_studs_inside({0},{1})\n".format(label, count)) @@ -78,15 +78,15 @@ 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_inner_circle_with_flats_to_sketch(side_studs_inside_pocket_sketch, DIMS_STUD_OUTER_RADIUS, - DIMS_STUD_INNER_RADIUS, DIMS_STUD_FLAT_THICKNESS, True, - 0, DIMS_SIDE_STUD_CENTRE_HEIGHT) + 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) # create array if needed if count > 1: geometry_indices = [range(0, len(side_studs_inside_pocket_sketch.Geometry) - 1)] side_studs_inside_pocket_sketch.addRectangularArray(geometry_indices, - Vector(DIMS_STUD_SPACING_INNER, 0, 0), False, + Vector(DIMS_STUD_SPACING, 0, 0), False, count, 1, True) side_studs_inside_pocket = self.brick.newObject("PartDesign::Pocket", label + "_side_studs_inside_pocket") diff --git a/Legify/TopStuds.py b/Legify/TopStuds.py index ab2746c..af4a53b 100644 --- a/Legify/TopStuds.py +++ b/Legify/TopStuds.py @@ -35,9 +35,9 @@ def _render_top_studs_outside(self, initial_width_offset, initial_depth_offset, if style == TopStudStyle.OPEN: - add_inner_circle_with_flats_to_sketch(top_studs_outside_pad_sketch, DIMS_STUD_OUTER_RADIUS, - DIMS_STUD_INNER_RADIUS, DIMS_STUD_FLAT_THICKNESS, False, - initial_width_offset, initial_depth_offset) + 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) @@ -47,15 +47,15 @@ def _render_top_studs_outside(self, initial_width_offset, initial_depth_offset, 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_INNER, 0), False, + Vector(0, DIMS_STUD_SPACING, 0), False, self.depth_count, self.width_count, True) elif self.width_count > 1 and self.depth_count == 1: top_studs_outside_pad_sketch.addRectangularArray(geometry_indices, - Vector(DIMS_STUD_SPACING_INNER, 0, 0), False, + Vector(DIMS_STUD_SPACING, 0, 0), False, self.width_count, self.depth_count, True) else: top_studs_outside_pad_sketch.addRectangularArray(geometry_indices, - Vector(0, DIMS_STUD_SPACING_INNER, 0), False, + Vector(0, DIMS_STUD_SPACING, 0), False, self.depth_count, self.width_count, True) top_studs_outside_pad = self.brick.newObject("PartDesign::Pad", "top_studs_outside_pad") @@ -66,17 +66,20 @@ def _render_top_studs_outside(self, initial_width_offset, initial_depth_offset, self.doc.recompute() # determine the stud outer edges - # TODO: failed to identify edges - 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) + # + # # 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 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)) @@ -96,15 +99,15 @@ def _render_top_studs_inside(self, initial_width_offset, initial_depth_offset): 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_INNER, 0), False, + Vector(0, DIMS_STUD_SPACING, 0), False, self.depth, self.width, True) elif self.width > 1 and self.depth == 1: top_studs_inside_pocket_sketch.addRectangularArray(geometry_indices, - Vector(DIMS_STUD_SPACING_INNER, 0, 0), False, + Vector(DIMS_STUD_SPACING, 0, 0), False, self.width, self.depth, True) else: top_studs_inside_pocket_sketch.addRectangularArray(geometry_indices, - Vector(0, DIMS_STUD_SPACING_INNER, 0), False, + Vector(0, DIMS_STUD_SPACING, 0), False, self.depth, self.width, True) top_studs_inside_pocket = self.brick.newObject("PartDesign::Pocket", "top_studs_inside_pocket") @@ -131,8 +134,8 @@ def render(self, context): self.top_datum_plane = context.top_datum_plane self.top_inside_datum_plane = context.top_inside_datum_plane - initial_width_offset = (self.width - self.width_count) * DIMS_STUD_SPACING_INNER / 2 - initial_depth_offset = (self.depth - self.depth_count) * DIMS_STUD_SPACING_INNER / 2 + initial_width_offset = (self.width - self.width_count) * DIMS_STUD_SPACING / 2 + initial_depth_offset = (self.depth - self.depth_count) * DIMS_STUD_SPACING / 2 self._render_top_studs_outside(initial_width_offset, initial_depth_offset, self.style) From 9f7c6061727d81281cebeb574f93f284c4c0ee60 Mon Sep 17 00:00:00 2001 From: vectronic Date: Mon, 20 Jul 2020 19:58:00 +0100 Subject: [PATCH 6/6] 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):