Skip to content

Instantly share code, notes, and snippets.

@CircuitRCAY
Last active June 7, 2021 14:19
Show Gist options
  • Save CircuitRCAY/faf0842d83aa14eec6028afeb10cb271 to your computer and use it in GitHub Desktop.
Save CircuitRCAY/faf0842d83aa14eec6028afeb10cb271 to your computer and use it in GitHub Desktop.
Blender Printer for Blender 2.9

Blender Braille Printer

This is a modified version of louisheath/braille-printer (which prints Grade 1 braille) for newer Blender versions, and to run in the Blender Python console.

import bpy
import sys
import os
braille = ([
[1, 0, 0, 0, 0, 0], # 00: a
[1, 0, 1, 0, 0, 0], # 01: b
[1, 1, 0, 0, 0, 0], # 02: c
[1, 1, 0, 1, 0, 0], # 03: d
[1, 0, 0, 1, 0, 0], # 04: e
[1, 1, 0, 1, 0, 0], # 05: f
[1, 1, 1, 1, 0, 0], # 06: g
[1, 0, 1, 1, 0, 0], # 07: h
[0, 1, 1, 0, 0, 0], # 08: i
[0, 1, 1, 1, 0, 0], # 09: j
[1, 0, 0, 0, 1, 0], # 10: k
[1, 0, 1, 0, 1, 0], # 11: l
[1, 1, 0, 0, 1, 0], # 12: m
[1, 1, 0, 1, 1, 0], # 13: n
[1, 0, 0, 1, 1, 0], # 14: o
[1, 1, 1, 0, 1, 0], # 15: p
[1, 1, 1, 1, 1, 0], # 16: q
[1, 0, 1, 1, 1, 0], # 17: r
[0, 1, 1, 0, 1, 0], # 18: s
[0, 1, 1, 1, 1, 0], # 19: t
[1, 0, 0, 0, 1, 1], # 20: u
[1, 0, 1, 0, 1, 1], # 21: v
[0, 1, 1, 1, 1, 1], # 22: w
[1, 1, 0, 0, 1, 1], # 23: x
[1, 1, 0, 1, 1, 1], # 24: y
[1, 0, 0, 1, 1, 1], # 25: z
[0, 0, 1, 0, 0, 0], # 26: ,
[0, 0, 1, 1, 0, 1], # 27: .
[0, 0, 1, 1, 0, 0], # 28: -
[0, 0, 1, 0, 1, 1], # 29: ?
[0, 0, 0, 0, 1, 1], # 30: _
[0, 0, 1, 1, 1, 0], # 31: !
[0, 0, 0, 0, 1, 0] # 32: "
])
english = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r' , 's', 't',
'u' , 'v', 'w', 'x', 'y', 'z', ',', '-', '?', '_',
'!', '"')
def isCapital(char):
capitals = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z')
for c in capitals:
if c == char:
return True
return False
def translate(string):
# List which will contain braille in form of lists
sentence = []
for char in string:
if isCapital(char): # capital prefix
sentence.append([0,0,0,0,0,1])
elif char.isnumeric(): # number prefix
sentence.append([0,1,0,1,1,1])
count = 0
for c in english:
if c == char.lower():
sentence.append(braille[count])
break
count = count + 1
return sentence
#input = [[1,0,1,1,0,0],[1,0,0,1,0,0],[1,0,1,0,1,0],[1,0,1,0,1,0],[1,0,0,1,1,0],[0,0,0,0,0,0],[0,1,1,1,0,1],[1,0,0,1,1,0],[1,0,1,1,1,0],[1,0,1,0,1,0],[1,1,0,1,0,0]]
input = translate("[insert text here]")
def createBraille(my_bool,x,y):
#create cube
bpy.ops.mesh.primitive_cube_add(enter_editmode=False, location=(x, y, 0.5), rotation=(1.57, 0, 0))
#change dimensions of cube to (1, 1, 1)
bpy.ops.transform.resize(value=(0.25, 0.25, 0.125), constraint_axis=(False, False, False), mirror=False, proportional_edit_falloff='SMOOTH', proportional_size=1)
if(my_bool):
#add cylinder
bpy.ops.mesh.primitive_cylinder_add(radius=0.125, depth=0.125, enter_editmode=False, location=(x, y, 0.625))
# when moving the cuboid = bpy.ops.transform.translate(value=(0.140409, 4.04676, 0.14149), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
initialX = 0
initialY = -8
letterCount = 0
lineCount = 0
for letter in input:
letterCount += 1
for i in range(0,3):
createBraille(letter[2*i],initialX,initialY)
createBraille(letter[2*i+1],initialX,initialY+0.5)
createBraille(0,initialX,initialY+1)
initialX += 0.5
initialY += 1.5
if letterCount == 6:
letterCount = 0
initialX = 1.5*lineCount
initialX += 1.5
lineCount += 1
initialY = -8
else:
initialX = 1.5*lineCount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment