forked from ajmendez/PyGRBL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualize.py
executable file
·73 lines (59 loc) · 2.21 KB
/
visualize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# visualize.py : A set of nice modifications for gcode
# [2012.08.21] - Mendez
import os, re, sys
from math import ceil
from datetime import datetime
from lib.image import Image
from lib.gcode import GCode
from lib.tool import Tool
from lib import argv
from lib.util import deltaTime
from clint.textui import puts, colored
FILEENDING ='' # keep it clean going to change file ending anyways
EXTRAARGS = dict(ext=dict(args=['-e','--eps'],
default='.pdf',
const='.eps',
action='store_const',
dest='ext',
help='''Specify for outputing an eps file rather than a pdf.''') )
def main(gfile, args=None):
start = datetime.now()
name = gfile if isinstance(gfile,str) else gfile.name
puts(colored.blue('Visualizing the file: %s\n Started: %s'%(name,datetime.now())))
# Read in the gcode
gcode = GCode(gfile, limit=None)
gcode.parse()
# parse the code into an array of tool moves
tool = Tool(gcode)
tool.uniq()
box = tool.boundBox()
# proces and save image
ext = args.ext if args is not None else '.pdf'
outfile = os.path.splitext(gfile.name)[0] + FILEENDING + ext
print box
print box[0:2]
image = Image(outfile, gridsize=box[0:2])
image.process(tool)
image.save()
# how long did this take?
puts(colored.green('Time to completion: %s'%(deltaTime(start))))
print
if __name__ == '__main__':
## I should wrap this in a __main__ section
# Initialize the args
start = datetime.now()
args = argv.arg(description='PyGRBL gcode imaging tool',
getFile=True, # get gcode to process
getMultiFiles=True, # accept any number of files
otherOptions=EXTRAARGS, # Install some nice things
getDevice=False) # We dont need a device
# optimize each file in the list
for gfile in args.gcode:
# only process things not processed before.
# c = re.match(r'(?P<drill>\.drill\.tap)|(?P<etch>\.etch\.tap)', gfile.name)
c = re.match(r'(.+)(\.tap)', gfile.name)
# c = True # HAX and accept everything
if c: # either a drill.tap or etch.tap file
main(gfile, args=args)
print '%s finished in %s'%(args.name,deltaTime(start))