示例#1
0
def mod(gfile):
    '''For each of the files to process either rotate, move, copy, or
  replicate the code.  General idea:
    read in ascii
    Process into a toolpath list.
    modify.
    Write out toolpath.'''

    start = datetime.now()
    puts(
        colored.blue('Modifying file: %s\n Started: %s' %
                     (gfile.name, datetime.now())))

    # Parse the gcode.
    gcode = GCode(gfile)
    gcode.parseAll()

    # Create a toolpath from the gcode
    # add in the index so that we can match it to the gcode

    out = []
    if args.move:
        loc = parse(args.move, getUnits=True)  # only one move at a time.
        puts(
            colored.blue('Moving!\n    (0,0) -> (%.3f,%.3f)' %
                         (loc[0], loc[1])))
        tool = Tool()
        # is the addIndex atribut even used any longer?
        tool.build(gcode, addIndex=True)
        tool.move(loc)  # ok well this should work
        gcode.update(tool)
        out.append([loc, gcode])

    if args.copy:
        locs = parse(args.copy, getUnits=True)
        puts(colored.blue('Copying!'))
        for loc in locs:
            puts(colored.blue('    (0,0) -> (%.3f,%.3f)' % (loc[0], loc[1])))
            gc = gcode.copy()
            tool = Tool()
            # is the addIndex atribut even used any longer?
            tool.build(gc, addIndex=True)
            tool.move(loc)
            gc.update(tool)
            out.append([loc, gc])

    # if args.replicate:
    #   nxy = map(int,parse(args.replicate)[0]) # ensure int, and only one
    #   puts(colored.blue('Replicating!\n     nx=%i, ny=%i)'%(nxy[0],nxy[1])))

    output = ''.join([o.getGcode(tag=args.name, start=l) for l, o in out])

    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
示例#2
0
文件: modify.py 项目: ajmendez/PyGRBL
def mod(gfile):
  '''For each of the files to process either rotate, move, copy, or
  replicate the code.  General idea:
    read in ascii
    Process into a toolpath list.
    modify.
    Write out toolpath.'''

  start = datetime.now()
  puts(colored.blue('Modifying file: %s\n Started: %s'%(gfile.name,datetime.now())))

  # Parse the gcode.
  gcode = GCode(gfile)
  gcode.parseAll()

  # Create a toolpath from the gcode
  # add in the index so that we can match it to the gcode


  out = []
  if args.move:
    loc = parse(args.move, getUnits=True) # only one move at a time.
    puts(colored.blue('Moving!\n    (0,0) -> (%.3f,%.3f)'%(loc[0],loc[1])))
    tool = Tool()
    # is the addIndex atribut even used any longer?
    tool.build(gcode, addIndex=True)
    tool.move(loc) # ok well this should work
    gcode.update(tool)
    out.append([loc,gcode])

  if args.copy:
    locs = parse(args.copy, getUnits=True)
    puts(colored.blue('Copying!'))
    for loc in locs:
      puts(colored.blue('    (0,0) -> (%.3f,%.3f)'%(loc[0],loc[1])))
      gc = gcode.copy()
      tool = Tool()
      # is the addIndex atribut even used any longer?
      tool.build(gc, addIndex=True)
      tool.move(loc)
      gc.update(tool)
      out.append([loc,gc])

  # if args.replicate:
  #   nxy = map(int,parse(args.replicate)[0]) # ensure int, and only one
  #   puts(colored.blue('Replicating!\n     nx=%i, ny=%i)'%(nxy[0],nxy[1])))

  output = ''.join([o.getGcode(tag=args.name,start=l) for l,o in out])

  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
示例#3
0
def zcorrect_file(gfile,surface_file_name = 'probe_test.out'):

    # Load the correction surface
    correction_surface = CorrectionSurface(surface_file_name)

    # keep track of time
    start = datetime.now()

    name = gfile if isinstance(gfile,str) else gfile.name
    puts(colored.blue('Z correcting the file: %s\n Started: %s'%(name,datetime.now())))

    # Load the gcode.
    gcode = GCode(gfile)
    #parse the Gcode
    gcode.parseAll()

    # start an empty list
    #out = []

    # need to get rid of use of 'loc'
    # loc = parse(args.move, getUnits=True) # only one move at a time.
    # puts(colored.blue('Moving!\n    (0,0) -> (%.3f,%.3f)'%(loc[0],loc[1])))

    # create a tool object (toolpath object)
    tool = Tool()
    # load the gcode into the tool object
    tool.build(gcode)
    # adjust the z position at each point by the given amount
    tool.zcorrect(correction_surface)

    ''' the follwing doe not work. is gcode.update(tool) broken?'''
    # load the changes back into the gcode object
    # append the modified g code to the empty list called out
    # out.append([gcode])
    # gcode.update(tool)
    # out = gcode
    # convert gcode to text format
    # output = ''.join([o.getGcode(tag=args.name) for o in out])
    # output = ''.join([out.getGcode()])

    '''instead the following simgle lin suffices'''
    '''is any info lost by doing it this way? E F M'''
    # generate a gcode file from the tool object
    output = tool.buildGcode()

    # get an output file name
    outfile = FILEENDING.join(os.path.splitext(gfile))
    print "outfile is:"
    print outfile
    # tell the user
    puts(colored.green('Writing: %s'%outfile))
    # write to file
    f = open(outfile,'w')
    f.write(output)
    '''
    with open(outfile,'w') as f:
        f.write(output)
    '''
    # how long did this take?
    puts(colored.green('Time to completion: %s'%(deltaTime(start))))
    print