Created
July 30, 2012 04:20
-
-
Save ahdinosaur/3204570 to your computer and use it in GitHub Desktop.
simple script to generate .dxf files for use in making grid beam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import dxfwrite | |
from dxfwrite import DXFEngine as dxf | |
def main(): | |
num_args = len(sys.argv) - 1 | |
if sys.argv[1] == "stick": | |
if num_args == 2: | |
return make_stick(float(sys.argv[2])) | |
elif num_args == 3: | |
return make_stick(float(sys.argv[2]), float(sys.argv[3])) | |
elif sys.argv[1] == "board": | |
if num_args == 5: | |
return make_board(float(sys.argv[2]), int(sys.argv[3]), float(sys.argv[4]), float(sys.argv[5])) | |
print "invalid arguments!" | |
print usage() | |
def usage(): | |
return """./gridbeam.py stick LENGTH WIDTH | |
./gridbeam.py board BOARD_LENGTH NUM_STICKS STICK_WIDTH SPACING_WIDTH""" | |
def make_stick(length, width=10.0): | |
assert (length > width), "length must be greater than width" | |
assert (length % width == 0), "length must be an even multiple of the width" | |
file_name = "%.1fx%.1fstick.dxf" % (length, width) | |
stick = dxf.drawing(file_name) | |
# make stick outline | |
stick_outline_layer = stick.add_layer('outline') | |
stick_outline = dxf.rectangle((0,0), width, length, layer='outline') | |
stick.add(stick_outline) | |
# make holes | |
stick_holes_layer = stick.add_layer('holes') | |
stick_holes = dxfwrite.DXFList() | |
half_width = width/2.0 | |
for hole_y in [(y*width + half_width) for y in range(int(length/width))]: | |
stick_holes.append(dxf.point((half_width, hole_y), layer='holes')) | |
stick.add(stick_holes) | |
stick.save() | |
print "stick '%s' created." % file_name | |
def make_board(length, num_sticks, stick_width=10.0, spacing=1.0): | |
assert (length > stick_width), "board length must be greater than stick width" | |
assert (length % stick_width == 0), "board length must be an even multiple of stick width" | |
file_name = "%dtimes%.1fx%.1fsticks.dxf" % (num_sticks, length, stick_width) | |
board = dxf.drawing(file_name) | |
for stick_num in range(num_sticks): | |
# make stick outlines | |
board_outline_layer = board.add_layer('outline%d' % stick_num) | |
board_outline = dxf.rectangle((0, (stick_num * (stick_width + spacing))), length, stick_width, layer='outline%d' % stick_num) | |
board.add(board_outline) | |
# make holes | |
board_holes_layer = board.add_layer('holes%d' % stick_num) | |
board_holes = dxfwrite.DXFList() | |
half_stick_width = stick_width/2.0 | |
for hole_x in [(x * stick_width + half_stick_width) for x in range(int(length/stick_width))]: | |
board_holes.append(dxf.point((hole_x, (stick_num * (stick_width + spacing)) + half_stick_width), layer='holes%d' % stick_num)) | |
board.add(board_holes) | |
board.save() | |
print "board '%s' created." % file_name | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment