v20
This commit is contained in:
parent
6e1bc8d944
commit
4b031fd98a
5 changed files with 115 additions and 118 deletions
|
|
@ -1,44 +1,50 @@
|
|||
# RACI-Konsolen-Board — Blender-Generator (bpy)
|
||||
# SLC-Workshop Tabletop · Einheiten: 1 Blender-Unit = 1 mm
|
||||
# Baut das Board parametrisch mit gefasten Kanten (Bevel), Mulden, Sektoren,
|
||||
# gravierten Labels, Action-Card-Steckschlitz; rendert eine Vorschau und
|
||||
# exportiert eine STL. Startgeruest v1 — in Blender 4.x getestet gegen die API,
|
||||
# einzelne Schritte sind per try/except abgesichert (Labels optional).
|
||||
#
|
||||
# Lauf: Blender -> Scripting -> Open -> Run ODER blender -b -P raci-board.py
|
||||
# RACI-Konsolen-Board (rund) — Blender-Generator (bpy) · v2
|
||||
# SLC-Workshop Tabletop · 1 Blender-Unit = 1 mm
|
||||
# Runde Puck-Flaeche, zentrale Acryl-Chip-Mulde (Ø40), 10 Sockel in 4 RACI-Sektoren
|
||||
# (R3 A1 C4 I2), gleich grosse Sektor-Woerter tangential um die Sockel, Kartenhalter
|
||||
# oben (Aussparung), Phasenname (DESIGN) unten im Innenkreis, Design-Blau.
|
||||
# Lauf: Scripting -> Open -> Run | blender -b -P raci-board.py
|
||||
|
||||
import bpy, bmesh, math, os
|
||||
from mathutils import Vector
|
||||
import bpy, math, os
|
||||
|
||||
# ----------------------------- Parameter (mm) -----------------------------
|
||||
BOARD_W, BOARD_D, BASE_H = 210.0, 210.0, 10.0
|
||||
EDGE_BEVEL, EDGE_SEG = 1.4, 4
|
||||
R_BOARD, BASE_H = 90.0, 12.0
|
||||
EDGE_BEVEL, EDGE_SEG = 1.6, 4
|
||||
|
||||
DIAL_CX, DIAL_CY = 0.0, -15.0
|
||||
CHIP_D, CHIP_DEP = 40.6, 1.8 # Acryl-Chip Ø40 x 2 mm
|
||||
NOTCH_D = 12.0
|
||||
CHIP_D, CHIP_DEP = 40.6, 1.8 # Acryl-Chip Ø40 x 2 mm
|
||||
NOTCH_D = 12.0
|
||||
SOCK_D, SOCK_DEP = 25.3, 1.5 # Figuren-Sockel Ø24,5
|
||||
SOCK_LEAD = 0.6
|
||||
RING_R = 64.0
|
||||
|
||||
SOCK_D, SOCK_DEP = 25.3, 1.5 # Figuren-Sockel Ø24,5
|
||||
RING_R = 48.0
|
||||
N_SOCK = 10 # Winkel ab oben (90°), 36°-Teilung
|
||||
RIDGE_H, RIDGE_W = 2.6, 3.2
|
||||
DIVIDERS = [72, -72, -144, 108]
|
||||
# Sektor-Mitten (fuer grosse Buchstaben) R3 A1 C4 I2
|
||||
LETTERS = [(90, "A"), (0, "C"), (-108, "I"), (162, "R")]
|
||||
PHASE_NAME = "DESIGN"
|
||||
PHASE_COLOR = (0.184, 0.502, 0.788, 1) # #2f80c9 Design-Blau
|
||||
|
||||
CARD_CY = 78.0
|
||||
CARD_BW, CARD_BD, CARD_BH = 84.0, 22.0, 16.0
|
||||
# Sektoren: Name, Wort-Mittenwinkel, Sockel-Winkel (Grad, 90=oben). Top frei fuer Karte.
|
||||
SECTORS = [
|
||||
("RESPONSIBLE", 165, [135, 165, 195]),
|
||||
("ACCOUNTABLE", 50, [50]),
|
||||
("CONSULTED", -20, [25, -5, -35, -65]),
|
||||
("INFORMED", -110, [-95, -125]),
|
||||
]
|
||||
DIVIDERS = [37.5, -80, -145] # Grenzen zwischen Sektoren (nicht im Karten-Spalt)
|
||||
RIDGE_H, RIDGE_W = 2.6, 3.4
|
||||
|
||||
WORD_SIZE, WORD_DEP = 5.0, 0.8
|
||||
WORD_R = RING_R + SOCK_D/2 + 9 # ausserhalb der Sockel
|
||||
DESIGN_SIZE, DESIGN_DEP = 9.0, 1.0
|
||||
DESIGN_POS = (0, -38) # unten im Innenkreis, gegenueber Kartenhalter
|
||||
|
||||
CARD_CY, CARD_BW, CARD_BD, CARD_BH = 70.0, 76.0, 20.0, 16.0
|
||||
SLOT_W, SLOT_T, SLOT_TILT = 63.0, 4.0, 12.0
|
||||
|
||||
LET_SIZE, LET_DEP = 11.0, 1.0
|
||||
WORD_SIZE, WORD_DEP = 5.0, 0.8
|
||||
TOP = BASE_H
|
||||
|
||||
def _outdir():
|
||||
d = os.path.dirname(bpy.data.filepath) # gesetzt, wenn .blend gespeichert
|
||||
d = os.path.dirname(bpy.data.filepath)
|
||||
if d: return d
|
||||
try: return os.path.dirname(os.path.abspath(__file__))
|
||||
except NameError: return os.path.expanduser("~") # Fallback: Benutzerordner
|
||||
except NameError: return os.path.expanduser("~")
|
||||
HERE = _outdir()
|
||||
STL_OUT = os.path.join(HERE, "raci-board.stl")
|
||||
PNG_OUT = os.path.join(HERE, "raci_preview.png")
|
||||
|
|
@ -46,8 +52,7 @@ print("Ausgabe-Ordner:", HERE)
|
|||
|
||||
# ----------------------------- Helfer -----------------------------
|
||||
def clear_scene():
|
||||
bpy.ops.object.select_all(action='SELECT')
|
||||
bpy.ops.object.delete(use_global=False)
|
||||
bpy.ops.object.select_all(action='SELECT'); bpy.ops.object.delete(use_global=False)
|
||||
for blk in (bpy.data.meshes, bpy.data.materials, bpy.data.curves):
|
||||
for d in list(blk):
|
||||
if d.users == 0: blk.remove(d)
|
||||
|
|
@ -55,16 +60,14 @@ def clear_scene():
|
|||
def cube(sx, sy, sz, loc):
|
||||
bpy.ops.mesh.primitive_cube_add(size=1, location=loc)
|
||||
o = bpy.context.object; o.scale = (sx, sy, sz)
|
||||
bpy.ops.object.transform_apply(scale=True)
|
||||
return o
|
||||
bpy.ops.object.transform_apply(scale=True); return o
|
||||
|
||||
def cyl(d, h, loc, verts=96):
|
||||
bpy.ops.mesh.primitive_cylinder_add(radius=d/2.0, depth=h, location=loc, vertices=verts)
|
||||
return bpy.context.object
|
||||
|
||||
def boolean(obj, tool, op='DIFFERENCE'):
|
||||
m = obj.modifiers.new("bool", 'BOOLEAN'); m.operation = op
|
||||
m.object = tool
|
||||
m = obj.modifiers.new("bool", 'BOOLEAN'); m.operation = op; m.object = tool
|
||||
try: m.solver = 'EXACT'
|
||||
except Exception: pass
|
||||
bpy.context.view_layer.objects.active = obj
|
||||
|
|
@ -72,145 +75,115 @@ def boolean(obj, tool, op='DIFFERENCE'):
|
|||
bpy.data.objects.remove(tool, do_unlink=True)
|
||||
|
||||
def apply_bevel(obj, width=EDGE_BEVEL, seg=EDGE_SEG, ang=30):
|
||||
m = obj.modifiers.new("bevel", 'BEVEL')
|
||||
m.width = width; m.segments = seg
|
||||
m = obj.modifiers.new("bevel", 'BEVEL'); m.width = width; m.segments = seg
|
||||
m.limit_method = 'ANGLE'; m.angle_limit = math.radians(ang)
|
||||
bpy.context.view_layer.objects.active = obj
|
||||
bpy.ops.object.modifier_apply(modifier=m.name)
|
||||
|
||||
def cut_text(board, body, x, y, rotz=0, size=LET_SIZE, dep=LET_DEP):
|
||||
def engrave(board, body, x, y, rotz=0, size=WORD_SIZE, dep=WORD_DEP):
|
||||
try:
|
||||
bpy.ops.object.text_add(location=(x, y, TOP - dep))
|
||||
t = bpy.context.object; t.data.body = body
|
||||
t.data.size = size; t.data.extrude = dep + 1.5
|
||||
t.data.align_x = 'CENTER'; t.data.align_y = 'CENTER'
|
||||
t = bpy.context.object; t.data.body = body; t.data.size = size
|
||||
t.data.extrude = dep + 1.5; t.data.align_x='CENTER'; t.data.align_y='CENTER'
|
||||
t.rotation_euler = (0, 0, math.radians(rotz))
|
||||
bpy.ops.object.convert(target='MESH')
|
||||
boolean(board, t, 'DIFFERENCE')
|
||||
bpy.ops.object.convert(target='MESH'); boolean(board, t, 'DIFFERENCE')
|
||||
except Exception as e:
|
||||
print("Label uebersprungen (%s): %s" % (body, e))
|
||||
|
||||
# ----------------------------- Aufbau -----------------------------
|
||||
clear_scene()
|
||||
|
||||
# Basisplatte + Kartenblock, beide gefast, dann vereinen
|
||||
base = cube(BOARD_W, BOARD_D, BASE_H, (0, 0, BASE_H/2))
|
||||
# Runde Platte + Kartenblock (oben), beide gefast, vereinen
|
||||
base = cyl(R_BOARD*2, BASE_H, (0, 0, BASE_H/2), verts=160)
|
||||
apply_bevel(base)
|
||||
block = cube(CARD_BW, CARD_BD, BASE_H + CARD_BH, (0, CARD_CY, (BASE_H + CARD_BH)/2))
|
||||
apply_bevel(block, width=1.0)
|
||||
boolean(base, block, 'UNION')
|
||||
|
||||
# Gefaste Ecke vorne rechts (Optik)
|
||||
cc = cube(28, 28, BASE_H + 4, (BOARD_W/2, -BOARD_D/2, BASE_H/2))
|
||||
cc.rotation_euler = (0, 0, math.radians(45)); bpy.ops.object.transform_apply(rotation=True)
|
||||
boolean(base, cc, 'DIFFERENCE')
|
||||
|
||||
# Chip-Mulde + Greifkerbe
|
||||
boolean(base, cyl(CHIP_D, 6, (DIAL_CX, DIAL_CY, TOP - CHIP_DEP + 3)), 'DIFFERENCE')
|
||||
boolean(base, cyl(NOTCH_D, 6, (DIAL_CX, DIAL_CY - CHIP_D/2, TOP - CHIP_DEP + 3)), 'DIFFERENCE')
|
||||
boolean(base, cyl(CHIP_D, 6, (0, 0, TOP - CHIP_DEP + 3)), 'DIFFERENCE')
|
||||
boolean(base, cyl(NOTCH_D, 6, (0, -CHIP_D/2, TOP - CHIP_DEP + 3)), 'DIFFERENCE')
|
||||
|
||||
# 10 Sockelmulden im Ring
|
||||
for i in range(N_SOCK):
|
||||
a = math.radians(90 - i * 36)
|
||||
x = DIAL_CX + RING_R * math.cos(a); y = DIAL_CY + RING_R * math.sin(a)
|
||||
boolean(base, cyl(SOCK_D, 6, (x, y, TOP - SOCK_DEP + 3)), 'DIFFERENCE')
|
||||
|
||||
# Deko-Rillen im Mittelfeld
|
||||
for rr in [24, 27, 30, 33]:
|
||||
ring = cyl(rr*2, 0.8, (DIAL_CX, DIAL_CY, TOP - 0.25))
|
||||
inner = cyl((rr-0.8)*2, 1.2, (DIAL_CX, DIAL_CY, TOP - 0.25))
|
||||
boolean(ring, inner, 'DIFFERENCE')
|
||||
boolean(base, ring, 'DIFFERENCE')
|
||||
# Sockelmulden (mit Einfuehr-Fase)
|
||||
for _, _, angles in SECTORS:
|
||||
for a in angles:
|
||||
x = RING_R*math.cos(math.radians(a)); y = RING_R*math.sin(math.radians(a))
|
||||
boolean(base, cyl(SOCK_D, 6, (x, y, TOP - SOCK_DEP + 3)), 'DIFFERENCE')
|
||||
|
||||
# Sektor-Trennstege (erhaben)
|
||||
ri, ro = CHIP_D/2 + 3, RING_R + SOCK_D/2 + 4
|
||||
for a in DIVIDERS:
|
||||
r = cube(ro - ri, RIDGE_W, RIDGE_H, ((ri+ro)/2, 0, TOP + RIDGE_H/2))
|
||||
r.rotation_euler = (0, 0, math.radians(a))
|
||||
# um Dial-Zentrum rotieren: erst an Zentrum verschieben
|
||||
r.location = (DIAL_CX + ((ri+ro)/2)*math.cos(math.radians(a)),
|
||||
DIAL_CY + ((ri+ro)/2)*math.sin(math.radians(a)), TOP + RIDGE_H/2)
|
||||
bpy.ops.object.transform_apply(rotation=False)
|
||||
rmid = (ri+ro)/2
|
||||
r = cube(ro-ri, RIDGE_W, RIDGE_H, (rmid*math.cos(math.radians(a)),
|
||||
rmid*math.sin(math.radians(a)), TOP + RIDGE_H/2))
|
||||
r.rotation_euler = (0, 0, math.radians(a)); bpy.ops.object.transform_apply(rotation=False)
|
||||
boolean(base, r, 'UNION')
|
||||
|
||||
# Action-Card-Steckschlitz (oben offen, nach hinten geneigt)
|
||||
slot = cube(SLOT_W, SLOT_T, 38, (0, CARD_CY, 22))
|
||||
slot.rotation_euler = (math.radians(-SLOT_TILT), 0, 0)
|
||||
bpy.ops.object.transform_apply(rotation=True)
|
||||
# Action-Card-Schlitz (oben offen, nach hinten geneigt)
|
||||
slot = cube(SLOT_W, SLOT_T, 40, (0, CARD_CY, 22))
|
||||
slot.rotation_euler = (math.radians(-SLOT_TILT), 0, 0); bpy.ops.object.transform_apply(rotation=True)
|
||||
boolean(base, slot, 'DIFFERENCE')
|
||||
|
||||
# Gravierte Rand-Linie
|
||||
outer = cube(BOARD_W-14, BOARD_D-14, 1.4, (0, 0, TOP-0.7))
|
||||
inner = cube(BOARD_W-17, BOARD_D-17, 2.0, (0, 0, TOP-0.7))
|
||||
boolean(outer, inner, 'DIFFERENCE'); boolean(base, outer, 'DIFFERENCE')
|
||||
# Gravierte Rand-Linie (rund)
|
||||
rim = cyl((R_BOARD-7)*2, 1.4, (0, 0, TOP-0.7))
|
||||
boolean(rim, cyl((R_BOARD-8.6)*2, 2.0, (0, 0, TOP-0.7)), 'DIFFERENCE')
|
||||
boolean(base, rim, 'DIFFERENCE')
|
||||
|
||||
# Labels: grosse R/A/C/I + Woerter
|
||||
for ang, ch in LETTERS:
|
||||
rl = RING_R + 13
|
||||
cut_text(base, ch, DIAL_CX + rl*math.cos(math.radians(ang)),
|
||||
DIAL_CY + rl*math.sin(math.radians(ang)))
|
||||
cut_text(base, "RESPONSIBLE", -(RING_R+29), DIAL_CY+6, 90, WORD_SIZE, WORD_DEP)
|
||||
cut_text(base, "CONSULTED", (RING_R+29), DIAL_CY+6, -90, WORD_SIZE, WORD_DEP)
|
||||
cut_text(base, "INFORMED", DIAL_CX, DIAL_CY-(RING_R+30), 0, WORD_SIZE, WORD_DEP)
|
||||
cut_text(base, "ACCOUNTABLE", DIAL_CX, CARD_CY - CARD_BD/2 - 8, 0, WORD_SIZE, WORD_DEP)
|
||||
# Sektor-Woerter: gleich gross, tangential um die Sockel
|
||||
for name, wc, _ in SECTORS:
|
||||
rot = (wc - 90) if math.sin(math.radians(wc)) >= 0 else (wc + 90) # lesbar tangential
|
||||
engrave(base, name, WORD_R*math.cos(math.radians(wc)), WORD_R*math.sin(math.radians(wc)), rot)
|
||||
|
||||
# Phasenname unten im Innenkreis
|
||||
engrave(base, PHASE_NAME, DESIGN_POS[0], DESIGN_POS[1], 0, DESIGN_SIZE, DESIGN_DEP)
|
||||
|
||||
base.name = "RACI-Board"
|
||||
# Auto-Smooth: flache Flaechen scharf, gefaste Kanten glatt
|
||||
try:
|
||||
bpy.ops.object.shade_auto_smooth(angle=math.radians(30)) # Blender >= 4.1
|
||||
try: bpy.ops.object.shade_auto_smooth(angle=math.radians(30))
|
||||
except Exception:
|
||||
try: bpy.ops.object.shade_flat()
|
||||
except Exception: pass
|
||||
|
||||
# ----------------------------- Material -----------------------------
|
||||
mat = bpy.data.materials.new("BoardBlue"); mat.use_nodes = True
|
||||
# ----------------------------- Material (Design-Blau) -----------------------------
|
||||
mat = bpy.data.materials.new("Phase"); mat.use_nodes = True
|
||||
bsdf = next((n for n in mat.node_tree.nodes if n.type == 'BSDF_PRINCIPLED'), None)
|
||||
if bsdf:
|
||||
bsdf.inputs["Base Color"].default_value = (0.09, 0.15, 0.30, 1) # dunkelblau
|
||||
bsdf.inputs["Base Color"].default_value = PHASE_COLOR
|
||||
try: bsdf.inputs["Roughness"].default_value = 0.5
|
||||
except Exception: pass
|
||||
base.data.materials.clear(); base.data.materials.append(mat)
|
||||
|
||||
# ----------------------------- Vorschau-Render (guarded) -----------------------------
|
||||
# ----------------------------- Vorschau-Render -----------------------------
|
||||
try:
|
||||
sc = bpy.context.scene
|
||||
# Welt etwas aufhellen
|
||||
try:
|
||||
wn = sc.world.node_tree.nodes
|
||||
bg = next((n for n in wn if n.type == 'BACKGROUND'), None)
|
||||
bg = next((n for n in sc.world.node_tree.nodes if n.type == 'BACKGROUND'), None)
|
||||
if bg: bg.inputs[1].default_value = 1.2
|
||||
except Exception: pass
|
||||
# Licht
|
||||
bpy.ops.object.light_add(type='SUN', location=(120, -160, 240))
|
||||
bpy.context.object.data.energy = 3.5
|
||||
bpy.ops.object.light_add(type='AREA', location=(-120, -60, 160))
|
||||
bpy.context.object.data.energy = 4000; bpy.context.object.data.size = 200
|
||||
# Kamera blickt aufs Board-Zentrum (Track-To), rahmt das ganze Board
|
||||
bpy.ops.object.empty_add(location=(0, 0, 4)); tgt = bpy.context.object
|
||||
bpy.ops.object.camera_add(location=(175, -220, 210)); cam = bpy.context.object
|
||||
cam.data.lens = 52
|
||||
bpy.ops.object.light_add(type='SUN', location=(140, -180, 260)); bpy.context.object.data.energy = 3.5
|
||||
bpy.ops.object.light_add(type='AREA', location=(-140, -60, 180))
|
||||
bpy.context.object.data.energy = 5000; bpy.context.object.data.size = 260
|
||||
bpy.ops.object.empty_add(location=(0, 0, 5)); tgt = bpy.context.object
|
||||
bpy.ops.object.camera_add(location=(215, -270, 250)); cam = bpy.context.object
|
||||
cam.data.lens = 50
|
||||
con = cam.constraints.new('TRACK_TO'); con.target = tgt
|
||||
con.track_axis = 'TRACK_NEGATIVE_Z'; con.up_axis = 'UP_Y'
|
||||
sc.camera = cam
|
||||
sc.render.resolution_x, sc.render.resolution_y = 1500, 1050
|
||||
sc.render.resolution_x, sc.render.resolution_y = 1500, 1100
|
||||
sc.render.filepath = PNG_OUT
|
||||
try: sc.render.engine = 'BLENDER_EEVEE_NEXT'
|
||||
except Exception:
|
||||
try: sc.render.engine = 'BLENDER_EEVEE'
|
||||
except Exception: pass
|
||||
bpy.ops.render.render(write_still=True)
|
||||
print("Vorschau:", PNG_OUT)
|
||||
bpy.ops.render.render(write_still=True); print("Vorschau:", PNG_OUT)
|
||||
except Exception as e:
|
||||
print("Render uebersprungen:", e)
|
||||
|
||||
# ----------------------------- STL-Export (versionstolerant) -----------------------------
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
base.select_set(True); bpy.context.view_layer.objects.active = base
|
||||
# ----------------------------- STL-Export -----------------------------
|
||||
bpy.ops.object.select_all(action='DESELECT'); base.select_set(True)
|
||||
bpy.context.view_layer.objects.active = base
|
||||
try:
|
||||
bpy.ops.wm.stl_export(filepath=STL_OUT, export_selected_objects=True) # Blender >= 4.1
|
||||
bpy.ops.wm.stl_export(filepath=STL_OUT, export_selected_objects=True)
|
||||
except Exception:
|
||||
try:
|
||||
bpy.ops.export_mesh.stl(filepath=STL_OUT, use_selection=True) # Blender <= 4.0
|
||||
except Exception as e:
|
||||
print("STL-Export fehlgeschlagen — bitte manuell File>Export>STL:", e)
|
||||
try: bpy.ops.export_mesh.stl(filepath=STL_OUT, use_selection=True)
|
||||
except Exception as e: print("STL-Export manuell noetig:", e)
|
||||
print("STL:", STL_OUT)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue