This code is kinda rough (spent a total of about 2 hours, most of it reading images.autodesk.com/adsk/files/dxf_format.pdf), but it might do about what you need it to. This code was made for converting simple lines, arcs and circles into G-Code for CNC machines.
Quote:String[] dxf;
String[] vport;
String[] entity;
String[][] ent;
String[][] code;
float viewcenterX = 0;
float viewcenterY = 0;
float viewWidthX = 1;
float viewWidthY = 1;
float aspectRatio = 1;
float zoom = 1;
void DXFImport(){
readDXF();
viewcenterX = float(vport[0]);
viewcenterY = float(vport[2]);
viewWidthY = float(vport[28]);
aspectRatio = float(vport[30]);
viewWidthX = viewWidthY * aspectRatio;
zoom = fixedheight / viewWidthY;
}
void drawDXF() {
noFill();
ellipseMode(CENTER);
pushMatrix();
translate(width/2, height/2);
scale(zoom);
strokeWeight(1/zoom);
translate(-viewcenterX, viewcenterY);
for(int i = 1; i < ent.length; i++){
if(ent[i][1].contains("LINE")){
if(ent[i][5].contains("HID")){stroke(0, 200, 0);}else{stroke(255);}
line(float(ent[i][7]), -float(ent[i][9]), float(ent[i][13]), -float(ent[i][15]));
}
if(ent[i][1].contains("ARC")){
float SA, EA;
SA = 360 - float(ent[i][17]);
EA = 360 - float(ent[i][15]);
if(SA > EA){EA += 360;}
if(ent[i][5].contains("HID")){stroke(0, 200, 0);}else{stroke(255);}
arc(float(ent[i][7]), -float(ent[i][9]), 2*float(ent[i][13]), 2*float(ent[i][13]), radians(SA), radians(EA));
}
if(ent[i][1].contains("CIRCLE")){
if(ent[i][5].contains("HID")){stroke(0, 200, 0);}else{stroke(255);}
ellipse(float(ent[i][7]), -float(ent[i][9]), 2*float(ent[i][13]), 2*float(ent[i][13]));
}
}
popMatrix();
}
void readDXF() {
dxf = loadStrings(folderPath);
vport = cutSection(dxf, "VPORT", "ENDTAB");
vport = cutSection(vport, " 12", " 43");
dxf = cutSection(dxf, "ENTITIES", "ENDSEC");
int numEntities = 0;
for(int i = 0; i < dxf.length; i++){
if(dxf[i].contains(" 0")){
dxf[i] = "ENTITY";
numEntities ++;
}
}
String joindxf;
joindxf = join(dxf, "~");
entity = split(joindxf, "ENTITY");
ent = new String[numEntities + 1][];
for(int i = 0; i <= numEntities; i++){
ent[i] = split(entity[i], "~");
}
}
String[] cutSection(String[] dxfs, String startcut, String endcut) {
int cutS = -1;
for(int i = 0; i < dxfs.length; i++){
if(dxfs[i].contains(startcut)){
cutS = i;
}
}
if(cutS == -1){println("SECTION " + startcut + " NOT FOUND.");}
dxfs = subset(dxfs, cutS + 1);
int cutF = -1;
for(int i = 0; i < dxfs.length; i++){
if(dxfs[i].contains(endcut)){
cutF = i;
break;
}
}
if(cutF == -1){println("SECTION NOT TERMINATED at " + endcut + ".");}
return subset(dxfs, 0, cutF-1);
}