We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProcessing DevelopmentLibraries,  Tool Development › request for .DXF *Import*
Page Index Toggle Pages: 1
request for .DXF *Import* (Read 3180 times)
request for .DXF *Import*
Mar 16th, 2006, 7:57pm
 
Some old posts have mentioned a .dxf importer for Processing, but I haven't been able to find it. I know there is an old .dxf exporter for the Alpha...

I need something that can draw lines from a .dxf file, preferably with layer control as I want to parse, draw, and then process them in sequence and I'd like it to be organized. I don't need 3D or much else.

I've tried other vector libraries for processing (SVG, etc.) and attempted to make use of Java DXF parsers, but they either don't have the features I need or are too complex for me to get into.

Was there ever a .dxf importer for Processing? I'd like to think if there is/ was it would be relatively straightforward. Otherwise, is there a simple way to parse the point data out of a .DXF file, preferably by layer?

Thanks.
Re: request for .DXF *Import*
Reply #1 - Mar 20th, 2006, 5:24am
 
Can you convert your models to OBJ? Tatsuya Saito has an obj importer that works fantastically.
Re: request for .DXF *Import*
Reply #2 - Mar 26th, 2006, 8:20am
 
I'm familiar with the .obj import, but I need to convert *lines*, not a 3D model. And I need them with layering intact.

.obj won't cut it.
Re: request for .DXF *Import*
Reply #3 - Apr 11th, 2006, 10:09am
 
Perhaps you can write your own?

I've looked at maya ascii formats and generaly copy-pasting data directly into a text file then writing a reader works great.

If your software can output some easily readable data, so much the better.
Re: request for .DXF *Import*
Reply #4 - Apr 12th, 2006, 1:29pm
 
i wrote an asc saver some time ago.. it's on my site, at http://seltar.wliia.org/sketch.php?pid=4 .. could probably give you some hint to how it's written.. maybe you could write an importer / exporter library for it..

-seltar
Re: request for .DXF *Import*
Reply #5 - Apr 26th, 2006, 9:00pm
 
seltar, thanks for the info.

i ended up coding my own parser using java, but it needs a lot of work to become a full processing library-- right now it's kind of a kludge.

i plan to work on it when i have more time this summer.
Re: request for .DXF *Import*
Reply #6 - Mar 18th, 2010, 6:14am
 
Hey,

anyone made any major steps on this subject?
Re: request for .DXF *Import*
Reply #7 - Mar 18th, 2010, 9:33pm
 
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);
}

Page Index Toggle Pages: 1