blendercam/scripts/addons/cam/puzzle_joinery.py

611 wiersze
24 KiB
Python
Czysty Zwykły widok Historia

2021-12-29 20:13:02 +00:00
# blender CAM ops.py (c) 2021 Alain Pelletier
#
# ***** BEGIN GPL LICENSE BLOCK *****
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ***** END GPL LICENCE BLOCK *****
2022-01-01 15:11:44 +00:00
# blender operators definitions are in this file. They mostly call the functions from curvecamcreate.py
from typing import Any
2021-12-29 20:13:02 +00:00
import bpy
from bpy.props import *
from bpy.types import Operator
from cam import utils, pack, polygon_utils_cam, simple, gcodepath, bridges, parametric, joinery
import shapely
from shapely.geometry import Point, LineString, Polygon
import mathutils
import math
DT = 1.025
2022-01-02 16:28:39 +00:00
2022-01-05 20:54:01 +00:00
def finger(diameter, stem=2):
2022-01-01 15:11:44 +00:00
# diameter = diameter of the tool for joint creation
# DT = Bit diameter tolerance
# stem = amount of radius the stem or neck of the joint will have
global DT
RESOLUTION = 12 # Data resolution
2022-01-04 16:28:31 +00:00
cube_sx = diameter * DT * (2 + stem - 1)
cube_ty = diameter * DT
cube_sy = 2 * diameter * DT
2021-12-29 20:13:02 +00:00
circle_radius = diameter * DT / 2
2022-01-04 16:28:31 +00:00
c1x = cube_sx / 2
c2x = cube_sx / 2
2022-01-01 15:11:44 +00:00
c2y = 3 * circle_radius
2021-12-29 20:13:02 +00:00
c1y = circle_radius
bpy.ops.curve.simple(align='WORLD', location=(0, cube_ty, 0), rotation=(0, 0, 0), Simple_Type='Rectangle',
Simple_width=cube_sx, Simple_length=cube_sy, use_cyclic_u=True, edit_mode=False)
2022-01-04 16:28:31 +00:00
bpy.context.active_object.name = "ftmprect"
2021-12-29 20:13:02 +00:00
bpy.ops.curve.simple(align='WORLD', location=(c2x, c2y, 0), rotation=(0, 0, 0), Simple_Type='Ellipse',
Simple_a=circle_radius,
2022-01-04 16:28:31 +00:00
Simple_b=circle_radius, Simple_sides=4, use_cyclic_u=True, edit_mode=False, shape='3D')
2021-12-29 20:13:02 +00:00
2022-01-04 16:28:31 +00:00
bpy.context.active_object.name = "ftmpcirc_add"
2021-12-29 20:13:02 +00:00
bpy.context.object.data.resolution_u = RESOLUTION
bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
simple.duplicate()
simple.mirrorx()
2021-12-29 20:13:02 +00:00
2022-01-04 16:28:31 +00:00
simple.union('ftmp')
simple.rename('ftmp', '_sum')
rc1 = circle_radius
bpy.ops.curve.simple(align='WORLD', location=(c1x, c1y, 0), rotation=(0, 0, 0), Simple_Type='Ellipse',
Simple_a=circle_radius, Simple_b=rc1, Simple_sides=4, use_cyclic_u=True, edit_mode=False,
shape='3D')
2021-12-29 20:13:02 +00:00
bpy.context.active_object.name = "_circ_delete"
bpy.context.object.data.resolution_u = RESOLUTION
2022-01-04 16:28:31 +00:00
bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
2021-12-29 20:13:02 +00:00
simple.duplicate()
simple.mirrorx()
2022-01-04 16:28:31 +00:00
simple.union('_circ')
2021-12-29 20:13:02 +00:00
2022-01-04 16:28:31 +00:00
simple.difference('_', '_sum')
bpy.ops.object.curve_remove_doubles()
simple.rename('_sum', "_puzzle")
2021-12-29 20:13:02 +00:00
2022-01-01 15:11:44 +00:00
def fingers(diameter, inside, amount, stem=1):
2022-01-01 15:11:44 +00:00
# diameter = diameter of the tool for joint creation
# inside = Tolerance in the joint receptacle
global DT # Bit diameter tolerance
2022-01-01 15:11:44 +00:00
# stem = amount of radius the stem or neck of the joint will have
# amount = the amount of fingers
xtranslate = -(4 + 2 * (stem - 1)) * (amount - 1) * diameter * DT / 2
finger(diameter, stem=stem) # generate male finger
2022-01-04 16:28:31 +00:00
simple.activeName("puzzlem")
simple.move(x=xtranslate, y=-0.00002)
2021-12-30 21:13:53 +00:00
2022-01-01 15:11:44 +00:00
if amount > 1:
# duplicate translate the amount needed (faster than generating new)
for i in range(amount - 1):
2022-01-01 15:11:44 +00:00
bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked": False, "mode": 'TRANSLATION'},
TRANSFORM_OT_translate={
"value": ((4 + 2 * (stem - 1)) * diameter * DT, 0, 0.0)})
simple.union('puzzle')
2021-12-29 20:13:02 +00:00
simple.activeName("fingers")
2021-12-29 20:13:02 +00:00
bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
2022-01-04 16:28:31 +00:00
# Receptacle is made using the silhouette offset from the fingers
if inside > 0:
bpy.ops.object.silhouete_offset(offset=inside, style='1')
simple.activeName('receptacle')
simple.move(y=-inside)
def twistf(name, length, diameter, tolerance, twist, tneck, tthick):
# add twist lock to receptacle
if twist:
joinery.interlock_twist(length, tthick, tolerance, cx=0, cy=0, rotation=0, percentage=tneck)
simple.rotate(math.pi/2)
simple.move(y=-tthick/2+2*diameter+2*tolerance)
simple.activeName('xtemptwist')
simple.makeActive(name)
simple.activeName('xtemp')
simple.union('xtemp')
simple.activeName(name)
2021-12-29 20:13:02 +00:00
def twistm(name, length, diameter, tolerance, twist, tneck, tthick, angle, x=0, y=0):
# add twist lock to male connector
global DT
if twist:
joinery.interlock_twist(length, tthick, tolerance, cx=0, cy=0, rotation=0, percentage=tneck)
simple.rotate(math.pi/2)
simple.move(y=-tthick/2+2*diameter*DT)
simple.rotate(angle)
simple.move(x=x, y=y)
simple.activeName('_twist')
simple.makeActive(name)
simple.activeName('_tmp')
simple.difference('_', '_tmp')
simple.activeName(name)
2021-12-29 20:13:02 +00:00
2022-01-05 20:54:01 +00:00
2022-01-01 15:11:44 +00:00
def bar(width, thick, diameter, tolerance, amount=0, stem=1, twist=False, tneck=0.5, tthick=0.01, which='MF'):
# width = length of the bar
# thick = thickness of the bar
# diameter = diameter of the tool for joint creation
# tolerance = Tolerance in the joint
# amount = amount of fingers in the joint 0 means auto generate
# stem = amount of radius the stem or neck of the joint will have
# twist = twist lock addition
# tneck = percentage the twist neck will have compared to thick
# tthick = thicknest of the twist material
# Which M,F, MF, MM, FF
global DT
2021-12-29 20:13:02 +00:00
if amount == 0:
amount = round(thick / ((4 + 2 * (stem - 1)) * diameter * DT)) - 1
2021-12-29 20:13:02 +00:00
bpy.ops.curve.simple(align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0), Simple_Type='Rectangle',
Simple_width=width, Simple_length=thick, use_cyclic_u=True, edit_mode=False)
2022-01-01 20:22:25 +00:00
simple.activeName('tmprect')
2021-12-29 20:13:02 +00:00
2022-01-01 15:11:44 +00:00
fingers(diameter, tolerance, amount, stem=stem)
2021-12-29 20:13:02 +00:00
2022-01-01 20:22:25 +00:00
if which == 'MM' or which == 'M' or which == 'MF':
simple.rename('fingers', '_tmpfingers')
simple.rotate(-math.pi / 2)
simple.move(x=width/2)
2022-01-01 20:22:25 +00:00
simple.rename('tmprect', '_tmprect')
2022-01-02 16:28:39 +00:00
simple.union('_tmp')
simple.activeName("tmprect")
twistm('tmprect', thick, diameter, tolerance, twist, tneck, tthick, -math.pi/2, x=width/2)
2021-12-30 21:13:53 +00:00
twistf('receptacle', thick, diameter, tolerance, twist, tneck, tthick)
2021-12-29 20:13:02 +00:00
simple.rename('receptacle', '_tmpreceptacle')
2022-01-01 20:22:25 +00:00
if which == 'FF' or which == 'F' or which == 'MF':
simple.rotate(-math.pi / 2)
simple.move(x=-width / 2)
2022-01-01 20:22:25 +00:00
simple.rename('tmprect', '_tmprect')
2022-01-03 19:43:58 +00:00
simple.difference('_tmp', '_tmprect')
2022-01-01 20:22:25 +00:00
simple.activeName("tmprect")
2021-12-29 20:13:02 +00:00
simple.removeMultiple("_") # Remove temporary base and holes
2022-01-01 20:22:25 +00:00
simple.removeMultiple("fingers") # Remove temporary base and holes
simple.rename('tmprect', 'Puzzle_bar')
simple.removeMultiple("tmp") # Remove temporary base and holes
simple.makeActive('Puzzle_bar')
2021-12-29 20:13:02 +00:00
2021-12-31 15:33:40 +00:00
def arc(radius, thick, angle, diameter, tolerance, amount=0, stem=1, twist=False, tneck=0.5, tthick=0.01, which='MF'):
2022-01-01 15:11:44 +00:00
# radius = radius of the curve
# thick = thickness of the bar
# angle = angle of the arc
# diameter = diameter of the tool for joint creation
# tolerance = Tolerance in the joint
# amount = amount of fingers in the joint 0 means auto generate
# stem = amount of radius the stem or neck of the joint will have
# twist = twist lock addition
# tneck = percentage the twist neck will have compared to thick
# tthick = thicknest of the twist material
# which = which joint to generate, Male Female MaleFemale M, F, MF
global DT # diameter tolerance for diameter of finger creation
2022-01-01 15:11:44 +00:00
if angle == 0: # angle cannot be 0
angle = 0.01
2022-01-01 13:05:54 +00:00
negative = False
if angle < 0: # if angle < 0 then negative is true
2022-01-01 13:05:54 +00:00
angle = -angle
negative = True
2021-12-30 21:13:53 +00:00
if amount == 0:
amount = round(thick / ((4 + 2 * (stem - 1)) * diameter * DT)) - 1
2022-01-01 15:11:44 +00:00
fingers(diameter, tolerance, amount, stem=stem)
twistf('receptacle', thick, diameter, tolerance, twist, tneck, tthick)
2022-01-01 15:11:44 +00:00
# generate arc
bpy.ops.curve.simple(align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0), Simple_Type='Segment',
Simple_a=radius - thick / 2,
Simple_b=radius + thick / 2, Simple_startangle=-0.0001, Simple_endangle=math.degrees(angle),
Simple_radius=radius, use_cyclic_u=False, edit_mode=False)
2021-12-30 21:13:53 +00:00
bpy.context.active_object.name = "tmparc"
2022-01-01 15:11:44 +00:00
simple.rename('fingers', '_tmpfingers')
2021-12-30 21:13:53 +00:00
simple.rotate(math.pi)
simple.move(x=radius)
2021-12-30 21:13:53 +00:00
bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
simple.rename('tmparc', '_tmparc')
2021-12-31 15:33:40 +00:00
if which == 'MF' or which == 'M':
simple.union('_tmp')
simple.activeName("base")
twistm('base', thick, diameter, tolerance, twist, tneck, tthick, math.pi, x=radius)
2021-12-31 15:33:40 +00:00
simple.rename('base', '_tmparc')
2021-12-30 21:13:53 +00:00
simple.rename('receptacle', '_tmpreceptacle')
simple.mirrory()
simple.move(x=radius)
2021-12-30 21:13:53 +00:00
bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
simple.rotate(angle)
simple.makeActive('_tmparc')
2021-12-30 21:13:53 +00:00
2021-12-31 15:33:40 +00:00
if which == 'MF' or which == 'F':
simple.difference('_tmp', '_tmparc')
2021-12-30 21:13:53 +00:00
bpy.context.active_object.name = "PUZZLE_arc"
2021-12-31 15:33:40 +00:00
bpy.ops.object.curve_remove_doubles()
2021-12-30 21:13:53 +00:00
simple.removeMultiple("_") # Remove temporary base and holes
simple.makeActive('PUZZLE_arc')
2021-12-31 15:33:40 +00:00
if which == 'M':
simple.rotate(-angle)
simple.mirrory()
2021-12-31 15:33:40 +00:00
bpy.ops.object.transform_apply(location=True, rotation=True, scale=False)
simple.rotate(-math.pi / 2)
simple.move(y=radius)
2021-12-31 15:33:40 +00:00
simple.rename('PUZZLE_arc', 'PUZZLE_arc_male')
elif which == 'F':
simple.mirrorx()
simple.move(x=radius)
simple.rotate(math.pi / 2)
2021-12-31 15:33:40 +00:00
simple.rename('PUZZLE_arc', 'PUZZLE_arc_receptacle')
else:
simple.move(x=-radius)
# bpy.ops.object.transform_apply(location=True, rotation=False, scale=False, properties=False)
#
if negative: # mirror if angle is negative
simple.mirrory()
#
# bpy.ops.object.curve_remove_doubles()
2021-12-31 15:33:40 +00:00
2022-01-01 13:05:54 +00:00
def arcbararc(length, radius, thick, angle, angleb, diameter, tolerance, amount=0, stem=1, twist=False,
tneck=0.5, tthick=0.01, which='MF'):
2022-01-01 15:11:44 +00:00
# length is the total width of the segments including 2 * radius and thick
# radius = radius of the curve
# thick = thickness of the bar
# angle = angle of the female part
# angleb = angle of the male part
# diameter = diameter of the tool for joint creation
# tolerance = Tolerance in the joint
# amount = amount of fingers in the joint 0 means auto generate
# stem = amount of radius the stem or neck of the joint will have
# twist = twist lock addition
# tneck = percentage the twist neck will have compared to thick
# tthick = thicknest of the twist material
# which = which joint to generate, Male Female MaleFemale M, F, MF
length -= (radius * 2 + thick) # adjust length to include 2x radius + thick
# generate base rectangle
2021-12-31 16:52:12 +00:00
bpy.ops.curve.simple(align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0), Simple_Type='Rectangle',
Simple_width=length * 1.005, Simple_length=thick, use_cyclic_u=True, edit_mode=False)
2021-12-31 16:52:12 +00:00
simple.activeName("tmprect")
2022-01-01 15:11:44 +00:00
# Generate male section and join to the base
2021-12-31 16:52:12 +00:00
if which == 'M' or which == 'MF':
2022-01-01 15:11:44 +00:00
arc(radius, thick, angleb, diameter, tolerance, amount=amount, stem=stem, twist=twist, tneck=tneck,
tthick=tthick, which='M')
simple.move(x=length / 2)
2021-12-31 16:52:12 +00:00
simple.activeName('tmp_male')
simple.selectMultiple('tmp')
bpy.ops.object.curve_boolean(boolean_type='UNION')
simple.activeName('male')
simple.removeMultiple('tmp')
simple.rename('male', 'tmprect')
2022-01-01 15:11:44 +00:00
# Generate female section and join to base
2021-12-31 16:52:12 +00:00
if which == 'F' or which == 'MF':
arc(radius, thick, angle, diameter, tolerance, amount=amount, stem=stem, twist=twist, tneck=tneck,
tthick=tthick, which='F')
simple.move(x=-length / 2)
2021-12-31 16:52:12 +00:00
simple.activeName('tmp_receptacle')
simple.union('tmp')
2021-12-29 20:13:02 +00:00
2022-01-01 13:05:54 +00:00
simple.activeName('arcBarArc')
simple.makeActive('arcBarArc')
2021-12-29 20:13:02 +00:00
2022-01-01 20:22:25 +00:00
def arcbar(length, radius, thick, angle, diameter, tolerance, amount=0, stem=1, twist=False,
tneck=0.5, tthick=0.01, which='MF'):
2022-01-01 20:22:25 +00:00
# length is the total width of the segments including 2 * radius and thick
# radius = radius of the curve
# thick = thickness of the bar
# angle = angle of the female part
# diameter = diameter of the tool for joint creation
# tolerance = Tolerance in the joint
# amount = amount of fingers in the joint 0 means auto generate
# stem = amount of radius the stem or neck of the joint will have
# twist = twist lock addition
# tneck = percentage the twist neck will have compared to thick
# tthick = thicknest of the twist material
# which = which joint to generate, Male Female MaleFemale M, F, MF
if which == 'M':
which = 'MM'
elif which == 'F':
which = 'FF'
length -= (radius * 2 + thick) # adjust length to include 2x radius + thick
# generate base rectangle
# Generate male section and join to the base
if which == 'MM' or which == 'MF':
bar(length, thick, diameter, tolerance, amount=amount, stem=stem, twist=twist, tneck=tneck, tthick=tthick,
which='M')
simple.activeName('tmprect')
if which == 'FF' or which == 'FM':
bar(length, thick, diameter, tolerance, amount=amount, stem=stem, twist=twist, tneck=tneck, tthick=tthick,
which='F')
simple.rotate(math.pi)
2022-01-01 20:22:25 +00:00
simple.activeName('tmprect')
# Generate female section and join to base
if which == 'FF' or which == 'MF':
arc(radius, thick, angle, diameter, tolerance, amount=amount, stem=stem, twist=twist, tneck=tneck,
tthick=tthick, which='F')
simple.move(x=-length / 2 * 0.998)
2022-01-01 20:22:25 +00:00
simple.activeName('tmp_receptacle')
2022-01-02 16:28:39 +00:00
simple.union('tmp')
2022-01-01 20:22:25 +00:00
simple.activeName('arcBar')
simple.removeMultiple('tmp')
if which == 'MM':
arc(radius, thick, angle, diameter, tolerance, amount=amount, stem=stem, twist=twist, tneck=tneck,
tthick=tthick, which='M')
2022-01-01 20:22:25 +00:00
bpy.ops.transform.mirror(orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)),
orient_matrix_type='GLOBAL', constraint_axis=(True, False, False))
simple.move(x=-length / 2 * 0.998)
2022-01-01 20:22:25 +00:00
simple.activeName('tmp_receptacle')
2022-01-02 16:28:39 +00:00
simple.union('tmp')
2022-01-01 20:22:25 +00:00
simple.activeName('arcBar')
simple.removeMultiple('tmp')
simple.makeActive('arcBar')
2022-01-02 16:28:39 +00:00
def multiangle(radius, thick, angle, diameter, tolerance, amount=0, stem=1, twist=False,
tneck=0.5, tthick=0.01, combination='MFF'):
2022-01-02 16:28:39 +00:00
# length is the total width of the segments including 2 * radius and thick
# radius = radius of the curve
# thick = thickness of the bar
# angle = angle of the female part
# diameter = diameter of the tool for joint creation
# tolerance = Tolerance in the joint
# amount = amount of fingers in the joint 0 means auto generate
# stem = amount of radius the stem or neck of the joint will have
# twist = twist lock addition
# tneck = percentage the twist neck will have compared to thick
# tthick = thicknest of the twist material
# which = which joint to generate, Male Female MaleFemale M, F, MF
2022-01-06 14:17:21 +00:00
r_exterior = radius + thick/2
r_interior = radius - thick/2
height = math.sqrt(r_exterior * r_exterior - radius * radius) + r_interior/4
bpy.ops.curve.simple(align='WORLD', location=(0, height, 0),
rotation=(0, 0, 0), Simple_Type='Rectangle',
2022-01-06 14:17:21 +00:00
Simple_width=r_interior, Simple_length=r_interior/2, use_cyclic_u=True,
edit_mode=False, shape='3D')
simple.activeName('tmp_rect')
bpy.ops.curve.simple(align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0), Simple_Type='Circle', Simple_sides=4,
2022-01-06 14:17:21 +00:00
Simple_radius=r_interior, shape='3D', use_cyclic_u=True, edit_mode=False)
2022-01-06 13:06:40 +00:00
simple.move(y=radius * math.tan(angle))
2022-01-06 14:17:21 +00:00
simple.activeName('tmpCircle')
2022-01-02 16:28:39 +00:00
arc(radius, thick, angle, diameter, tolerance, amount=amount, stem=stem, twist=twist, tneck=tneck, tthick=tthick,
which='MF')
simple.activeName('tmp_arc')
2022-01-06 14:17:21 +00:00
if combination == 'MFF':
simple.duplicate()
simple.mirrorx()
elif combination == 'MMF':
arc(radius, thick, angle, diameter, tolerance, amount=amount, stem=stem, twist=twist, tneck=tneck,
tthick=tthick,
which='M')
simple.activeName('tmp_arc')
simple.mirrory()
simple.rotate(math.pi/2)
simple.union("tmp_")
2022-01-06 13:06:40 +00:00
simple.difference('tmp', 'tmp_')
2022-01-06 14:17:21 +00:00
simple.activeName('multiAngle60')
2022-01-02 16:28:39 +00:00
def t(length, thick, diameter, tolerance, amount=0, stem=1, twist=False, tneck=0.5, tthick=0.01, combination='MF',
base_gender='M', corner=False):
2022-01-03 13:42:40 +00:00
if corner:
if combination == 'MF':
base_gender = 'M'
combination = 'f'
elif combination == 'F':
base_gender = 'F'
combination = 'f'
elif combination == 'M':
base_gender = 'M'
combination = 'm'
2022-01-02 16:28:39 +00:00
bar(length, thick, diameter, tolerance, amount=amount, stem=stem, twist=twist, tneck=tneck,
tthick=tthick, which=base_gender)
simple.activeName('tmp')
fingers(diameter, tolerance, amount=amount, stem=stem)
2022-01-03 13:42:40 +00:00
if combination == 'MF' or combination == 'M' or combination == 'm':
2022-01-02 16:28:39 +00:00
simple.makeActive('fingers')
simple.move(y=thick / 2)
simple.duplicate()
2022-01-02 16:28:39 +00:00
simple.activeName('tmp')
simple.union('tmp')
if combination == 'M':
simple.makeActive('fingers')
simple.mirrory()
2022-01-02 16:28:39 +00:00
simple.activeName('tmp')
simple.union('tmp')
2022-01-03 13:42:40 +00:00
if combination == 'MF' or combination == 'F' or combination == 'f':
2022-01-02 16:28:39 +00:00
simple.makeActive('receptacle')
simple.move(y=-thick / 2)
simple.duplicate()
2022-01-02 16:28:39 +00:00
simple.activeName('tmp')
simple.difference('tmp', 'tmp')
if combination == 'F':
simple.makeActive('receptacle')
simple.mirrory()
2022-01-02 16:28:39 +00:00
simple.activeName('tmp')
simple.difference('tmp', 'tmp')
simple.removeMultiple('receptacle')
simple.removeMultiple('fingers')
simple.rename('tmp', 't')
simple.makeActive('t')
2022-01-01 20:22:25 +00:00
2022-01-07 13:43:45 +00:00
def curved_t(length, thick, radius, diameter, tolerance, amount=0, stem=1, twist=False, tneck=0.5, tthick=0.01,
combination='MF', base_gender='M'):
bar(length, thick, diameter, tolerance, amount=amount, stem=stem, twist=twist, tneck=tneck,
tthick=tthick, which=combination)
simple.activeName('tmpbar')
bpy.ops.curve.simple(align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0), Simple_Type='Rectangle',
Simple_width=3 * radius, Simple_length=thick, use_cyclic_u=True, edit_mode=False)
simple.activeName("tmp_rect")
if base_gender == 'MF':
arc(radius, thick, math.pi/2, diameter, tolerance, amount=amount, stem=stem, twist=twist, tneck=tneck, tthick=tthick,
which='M')
simple.move(-radius)
simple.activeName('tmp_arc')
arc(radius, thick, math.pi/2, diameter, tolerance, amount=amount, stem=stem, twist=twist, tneck=tneck, tthick=tthick,
which='F')
simple.move(radius)
simple.mirrory()
simple.activeName('tmp_arc')
simple.union('tmp_arc')
simple.duplicate()
simple.mirrorx()
simple.union('tmp_arc')
simple.difference('tmp_', 'tmp_arc')
else:
arc(radius, thick, math.pi/2, diameter, tolerance, amount=amount, stem=stem, twist=twist, tneck=tneck, tthick=tthick,
which=base_gender)
simple.activeName('tmp_arc')
simple.difference('tmp_', 'tmp_arc')
if base_gender == 'M':
simple.move(-radius)
else:
simple.move(radius)
simple.duplicate()
simple.mirrorx()
simple.union('tmp')
simple.activeName('curved_t')
2022-01-03 19:43:58 +00:00
def mitre(length, thick, angle, angleb, diameter, tolerance, amount=0, stem=1, twist=False,
tneck=0.5, tthick=0.01, which='MF'):
2022-01-03 19:43:58 +00:00
# length is the total width of the segments including 2 * radius and thick
# radius = radius of the curve
# thick = thickness of the bar
# angle = angle of the female part
# angleb = angle of the male part
# diameter = diameter of the tool for joint creation
# tolerance = Tolerance in the joint
# amount = amount of fingers in the joint 0 means auto generate
# stem = amount of radius the stem or neck of the joint will have
# twist = twist lock addition
# tneck = percentage the twist neck will have compared to thick
# tthick = thicknest of the twist material
# which = which joint to generate, Male Female MaleFemale M, F, MF
# generate base rectangle
bpy.ops.curve.simple(align='WORLD', location=(0, -thick / 2, 0), rotation=(0, 0, 0), Simple_Type='Rectangle',
Simple_width=length * 1.005 + 4 * thick, Simple_length=thick, use_cyclic_u=True,
edit_mode=False,
2022-01-03 19:43:58 +00:00
shape='3D')
simple.activeName("tmprect")
2022-01-03 20:49:32 +00:00
# generate cutout shapes
2022-01-03 19:43:58 +00:00
bpy.ops.curve.simple(align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0), Simple_Type='Rectangle',
Simple_width=4 * thick, Simple_length=6 * thick, use_cyclic_u=True, edit_mode=False,
shape='3D')
simple.move(x=2 * thick)
simple.rotate(angle)
simple.move(x=length / 2)
2022-01-03 19:43:58 +00:00
simple.activeName('tmpmitreright')
bpy.ops.curve.simple(align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0), Simple_Type='Rectangle',
Simple_width=4 * thick, Simple_length=6 * thick, use_cyclic_u=True, edit_mode=False,
shape='3D')
simple.move(x=2 * thick)
simple.rotate(angleb)
simple.move(x=length / 2)
simple.mirrorx()
2022-01-03 19:43:58 +00:00
simple.activeName('tmpmitreleft')
simple.difference('tmp', 'tmprect')
simple.makeActive('tmprect')
fingers(diameter, tolerance, amount, stem=stem)
# Generate male section and join to the base
if which == 'M' or which == 'MF':
2022-01-03 19:48:47 +00:00
simple.makeActive('fingers')
simple.duplicate()
2022-01-03 19:48:47 +00:00
simple.activeName('tmpfingers')
simple.rotate(angle - math.pi / 2)
h = thick / math.cos(angle)
2022-01-03 19:43:58 +00:00
h /= 2
simple.move(x=length / 2 + h * math.sin(angle), y=-thick / 2)
2022-01-03 19:43:58 +00:00
if which == 'M':
simple.rename('fingers', 'tmpfingers')
simple.rotate(angleb - math.pi / 2)
h = thick / math.cos(angleb)
2022-01-03 19:43:58 +00:00
h /= 2
simple.move(x=length / 2 + h * math.sin(angleb), y=-thick / 2)
simple.mirrorx()
2022-01-03 19:43:58 +00:00
simple.union('tmp')
simple.activeName('tmprect')
# Generate female section and join to base
if which == 'MF' or which == 'F':
simple.makeActive('receptacle')
simple.mirrory()
simple.duplicate()
2022-01-03 19:43:58 +00:00
simple.activeName('tmpreceptacle')
simple.rotate(angleb - math.pi / 2)
h = thick / math.cos(angleb)
2022-01-03 19:43:58 +00:00
h /= 2
simple.move(x=length / 2 + h * math.sin(angleb), y=-thick / 2)
simple.mirrorx()
2022-01-03 19:43:58 +00:00
if which == 'F':
simple.rename('receptacle', 'tmpreceptacle2')
simple.rotate(angle - math.pi / 2)
h = thick / math.cos(angle)
2022-01-03 19:43:58 +00:00
h /= 2
simple.move(x=length / 2 + h * math.sin(angle), y=-thick / 2)
2022-01-03 19:43:58 +00:00
simple.difference('tmp', 'tmprect')
simple.removeMultiple('receptacle')
simple.removeMultiple('fingers')
2022-01-03 19:48:47 +00:00
simple.rename('tmprect', 'mitre')