Example #1
0
def main(etch_file, args=None):
    start = datetime.now()
    name = etch_file if isinstance(etch_file, str) else etch_file.name
    puts(
        colored.blue('Visualizing the file: %s\n Started: %s' %
                     (name, datetime.now())))

    # Read in the gcode
    gcode = GCode(etch_file, limit=None)
    gcode.parse()

    # parse the code into an array of tool moves
    tool = Tool(gcode)
    box = tool.boundBox()

    # proces and save image
    outfile = os.path.splitext(etch_file.name)[0] + '.eps'
    print box
    print box[0:2]
    image = Drawing(outfile)  #, bbox=box)
    image.process(tool)
    image.save()

    # how long did this take?
    puts(colored.green('Time to completion: %s' % (deltaTime(start))))
    print
Example #2
0
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
Example #3
0
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
Example #4
0
def main(etch_file, args=None):
	start = datetime.now()
	name = etch_file if isinstance(etch_file,str) else etch_file.name
	puts(colored.blue('Visualizing the file: %s\n Started: %s'%(name,datetime.now())))

	# Read in the gcode
	gcode = GCode(etch_file, limit=None)
	gcode.parse()
	
	# parse the code into an array of tool moves
	tool = Tool(gcode)
	box = tool.boundBox()
	
	# proces and save image
	outfile = os.path.splitext(etch_file.name)[0] + '.eps'
	print box
	print box[0:2]
	image = Drawing(outfile)#, bbox=box)
	image.process(tool)
	image.save()

	# how long did this take?
  	puts(colored.green('Time to completion: %s'%(deltaTime(start))))
  	print
Example #5
0
def opt(gfile, offset=(0.0,0.0,0.0), rotate=False):
  '''Optimization core function:
  Reads in gCode ascii file.
  Processes gcode into toolpath list
  figures out milling.
  Reorders milling to get optimal
  Writes out to new file.'''
  
  start = datetime.now()
  puts(colored.blue('Optimizing file: %s\n Started: %s'%(gfile.name,datetime.now())))
  
  # Parse the gcode from the ascii to a list of command numbers and location
  gcode = GCode(gfile)
  gcode.parse()
  
  # Take the list and make a toolpath out of it. A toolpath is a list of locations
  # where the bit needs to be moved / milled : [ [x,y,z,t], ...]
  tool = Tool(gcode)
  tool.offset(offset)
  tool.rotate(rotate)
  
  tool.groupMills()
  puts(colored.blue('Toolpath length: %.2f inches, (mill only: %.2f)'%(tool.length(),tool.millLength())))
  if args.setMillHeight:
    tool.setMillHeight(Z_MILL,Z_SPOT)
  tool.uniqMills()
  
  # This starts the optimization process:
  # start at here, and go to the next path which is closest is the overall plan
  puts(colored.blue('Starting Optimization:'))
  here = [0.0]*3 # start at the origin
  newMills = []  # accumulate mills here
  k = 0
  while len(tool.mills) > 0:
    # No Optimization
    # mill = tool.mills.pop(0)

    # Basic optimization, find the next closest one and use it.
    # mill = tool.getNextMill(here)

    # Advanced Optimization:  Assumes that each mill path closed, so finds 
    #  the mill path which is close to the point and reorders it to be so
    mill = tool.getClosestMill(here)
    
    # you were here, now you are there
    # move mills and update location
    newMills.append(mill) 
    here = newMills[-1][-1]
    
    k += 1
    if (k%10) == 0:
      sys.stdout.write('.')
      sys.stdout.flush()
    
  tool.mills.extend(newMills)
  tool.reTool(Z_MOVE)
  tool.uniq()
  puts(colored.blue('Toolpath length: %.2f inches, (mill only: %.2f)'%(tool.length(),tool.millLength())))

  # Save this with the _opt file ending.
  output = tool.buildGcode()
  outfile = FILEENDING.join(os.path.splitext(gfile.name))
  puts(colored.green('Writing: %s'%outfile))
  with open(outfile,'w') as f:
    f.write(output)
  
  # how long did this take?
  puts(colored.green('Time to completion: %s'%(deltaTime(start))))
  print