Example #1
0
def process(input, output):
    # read the DXF file
    drawing = readDXF(input)

    # millcrum contents buffer
    mcBuffer = ''

    # process LINE
    lines     = drawing.entities.get_type('line')
    polylines = process_lines(lines)
    
    if polylines:
        for polyline in polylines:
            mcBuffer+= mcPolygon(polyline)

    # process POLYLINE
    polylines = drawing.entities.get_type("polyline")
    polylines.extend(drawing.entities.get_type("lwpolyline"))
    polylines = process_polylines(polylines)

    if polylines:
        for polyline in polylines:
            mcBuffer+= mcPolygon(polyline)

    # process ARCS
    arcs = drawing.entities.get_type('arc')
    arcs = process_arcs(arcs)
    
    if arcs:
        for arc in arcs:
            mcBuffer+= mcPolygon(arc)

    # surface size
    width  = (maxX if maxX else 100) + 10
    height = (maxY if maxY else 100) + 10

    # millcrum header
    buffer = 'var mc = new Millcrum({units:\'mm\',diameter:3,passDepth:1,step:1,rapid:2000,plunge:100,cut:600,zClearance:5,returnHome:true});\n\n'
    buffer+= 'mc.surface('+str(width)+','+str(height)+');\n\n'

    # millcrum contents
    buffer+= mcBuffer + '\n'

    # millcrum footer
    buffer+= 'mc.get();\n'

    # output message
    if mcBuffer == '':
        print 'Sorry, nothing to display...'
    if output == 'stdout':
        print buffer
    else:
        print 'input  :', input
        print 'output :', output
        # write to output file
        f = open(output, 'w')
        f.write(buffer+'\n')
        f.close()
def process(filename):
    # process a file
    minX = 0
    maxX = 0
    minY = 0
    maxY = 0
    drawing = readDXF(filename)
    mcOut = ''

    lines = drawing.entities.get_type("line")    
    for line in lines:
        shape = drawLine(line)
        if shape:
            print "\nFOUND UNSUPPORTED LINE OBJECT\n"

    arcs = drawing.entities.get_type("arc")    
    for arc in arcs:
        shape = drawArc(arc)
        if shape:
            print "\nFOUND UNSUPPORTED ARC OBJECT\n"

    polylines = drawing.entities.get_type("polyline")
    polylines.extend(drawing.entities.get_type("lwpolyline"))
    i = 0
    for polyline in polylines:
        shape = drawPolyline(polyline)
        if shape:

            # to remove duplicate points
            lastPoint = [0,0]

            mcOut += "\n// "+polyline.layer+"\n"
            mcOut += "var polygon"+str(i)+" = {type:'polygon',name:'"+polyline.layer+"',points:["
            pl = 0
            for p in shape:

                if (lastPoint[0] != p[0] or lastPoint[1] != p[1]) or pl == 0:
                    # this is a novel point or the first point
		    mcOut += '['+str(p[0])+','+str(p[1])+'],';

                    # calculate min and max
                    if p == 0 and i == 0:
                        minX = p1[0]
                        maxX = p1[0]
                        minY = p1[1]
                        maxY = p1[1]
                    else:
                        if p[0] < minX:
                            minX = p[0]
                        elif p[0] > maxX:
                            maxX = p[0]
                        if p[1] < minY:
                            minY = p[1]
                        elif p[1] > maxY:
                            maxY = p[1]

                    lastPoint[0] = p[0]
                    lastPoint[1] = p[1]
                pl += 1

            mcOut += "]};"
            mcOut += "\nmc.cut('centerOnPath',polygon"+str(i)+", 4, [0,0]);\n"
            i += 1

    mcOut += '\nmc.get();\n'

    if minX > 0:
        minX = 0;
    if minY > 0:
        minY = 0;

    totalX = maxX-minX
    totalY = maxY-minY
    mcOut = 'var tool = {units:\'mm\',diameter:6.35,passDepth:4,step:1,rapid:2000,plunge:100,cut:600,zClearance:5,returnHome:true};\n\nvar mc = new Millcrum(tool);\n\nmc.surface('+str(totalX*2)+','+str(totalY*2)+');\n' + mcOut

    if len(sys.argv) > 2:
        # output to file
        print "PROCESSING DXF FILE "+sys.argv[1]+" TO "+sys.argv[2]+"\n"
        f = open(sys.argv[2], 'w')
        f.write(mcOut+"\n")
        f.close()
    else:
        # output to STDOUT
        print "PROCESSING DXF FILE "+sys.argv[1]+" TO STDOUT\n"
        print mcOut+"\n"
Example #3
0
def process(filename):
    "this does the translation of the dxf contents into HeeksPython Part objects"
    global drawing 
    header_collector = []
    collector = []
    layer_collector = []
    i = 1
    drawing = readDXF(filename)
    global layers
    layers = []


    # drawing lines    
    lines = drawing.entities.get_type("line")    
    for line in lines:
        shape = drawLine(line)
        if shape:
            collector.append(shape)
            layers.append(line.layer)
            i+=1
            collector.append("e"+str(i)+ "=cad.getlastobj()\n")
            collector.append("cad.add("+rename(line.layer)+",e"+str(i)+")\n")
    string = "".join(collector) 

    # drawing arcs
    arcs = drawing.entities.get_type("arc")    
    for arc in arcs:
        shape = drawArc(arc)
        if shape:
            collector.append(shape)
            layers.append(arc.layer)
            i+=1
            collector.append("e"+str(i)+ "=cad.getlastobj()\n")
            collector.append("cad.add("+rename(arc.layer)+",e"+str(i)+")\n")
    string = "".join(collector) 

    # drawing polylines
    polylines = drawing.entities.get_type("polyline")
    polylines.extend(drawing.entities.get_type("lwpolyline"))

    for polyline in polylines:
        shape,poly_index = drawPolyline(polyline,i)
        i = poly_index
        if shape:
            collector.append(shape)
            layers.append(polyline.layer)

    string = "".join(collector)  

    #print "import HeeksPython as cad"
    #heeksimport = importLine()
    #print heeksimport
    #collector.append(heeksimport)
    #string = "".join(collector) 
    #print string
    #string = collector

    #string1 = "import HeeksPython as cad\n"

    header_collector.append("import HeeksPython as cad\n")
    string1 = "".join(header_collector) 
    print string1

    LayerList = list(set(layers))
    for LL in LayerList:
        print "cad.sketch()\n"
        print (rename(LL) + "=cad.getlastobj()\n")
        #layer_collector.append("cad.sketch()\n")
        #layer_collector.append(rename(LL) + "=cad.getlastobj()\n")
        #string2 = "".join(layer_collector)
        #print string2


 
    print string 

    for LL in LayerList:
        print ("cad.reorder("+rename(LL)+ ")\n" )