DXF Export Points

edited July 2017 in Library Questions

Is there a way to export points to DXF using the DXF library. From what I have attempted, read, and seen this cannot be done. It appears DXF export only works for lines, arcs, and 3D shapes but not points. If this is the case, could this feature (exporting points to DXF) please be implemented?

Tagged:

Answers

  • use a triangle where x, y, z for all 3 vertices is the same.

  • or a line from x, y, z to x, y, z

  • Is your goal to create the appearance of a point?

    Or is your goal to create a DXF POINT entity in the file as per the DXF specification, e.g. for reference?

    http://images.autodesk.com/adsk/files/autocad_2012_pdf_dxf-reference_enu.pdf#page131

  • edited July 2017

    (i read that earlier today but it wasn't clear whether the DXF POINT entity (or the VERTEX on p149) could exist on its own or whether it was something that just defined part of a larger entity)

    (certainly if you try the dxf code on the library page with only a point in it, it gives you an error (one which is a bit cryptic:

    "RawDXF can only be used with beginRaw(), because it only supports lines and triangles"

    but i think you're right and that's probably more a library deficiency than the file format not supporting it))

    with a line from 0, 0 to 0, 0 i get

    0
    SECTION
    2
    ENTITIES
    0
    LINE
    8
    0
    10 // startx
    -250.0
    20 // starty
    -250.0
    30 // startz
    -433.0127
    11 // endx
    -250.0
    21 // endy
    -250.0
    31 // endz
    -433.0127
    0
    ENDSEC
    0
    EOF
    

    but i haven't tried decoded that yet

    (ok, added // comments above. the canvas is 500x500 and i'm drawing at 0, 0. it's using the centre as the origin so my point is -250, -250. no idea about the z...)

  • @koogs @jeremydouglass

    The goal is to create a single DXF POINT. The DXF point created as an output of the processing sketch will then be sent to a laser. My concern with making a line using the same two points is that I cannot have any points duplicated as it increases the runtime for the laser on an already long process.

    If this is a library deficiency, I would really appreciate if it could be updated to allow the export of DXF POINT entities.

  • edited July 2017

    Right. Maybe something like:

    1. at 276, add void writePoint(){}
    2. at 384, add if-point-call-writePoint()
    3. at 324, add a condition for POINT

    A key question is what to do at 324 given a condition for POINT given that createShape() only supports "ELLIPSE, RECT, ARC, TRIANGLE, SPHERE, BOX, QUAD, or LINE". - https://processing.org/reference/createShape_.html as per @koogs below

    You need to figure out how you are encoding points alongside triangles etc. in Processing before you translate them into DXF. A demo sketch would really help.

  • @koogs @jeremydouglass Thank you guys for the help. Writing or modifying a library is above my skill level in processing. I'm an ME so while enjoy programming side quite a bit I would need some help with modifying the library.

    I have a processing sketch right now which takes a .txt file and extracts data from the file for conversion to .csv. I then copy the data from the .csv and plot a couple thousand points into AutoCAD. What I'm trying to do is skip the intermediary .csv and plot the data straight to a dxf.

  • given that createShape() only supports "ELLIPSE, RECT, ARC, TRIANGLE, SPHERE, BOX, QUAD, or LINE".

    the PShape javadoc says that POINTS are ok too, so i tried it

    PShape s;
    
    void setup() {
      size(100, 100, P2D);
      s = createShape();
      s.beginShape(POINTS);
      for (int i = 0 ; i < 100 ; i++) {
        s.vertex(random(width), random(height));
      }
      s.endShape();
    }
    
    void draw() {
      shape(s, 0, 0);
    }
    

    looks ok.

  • edited July 2017

    Is there something I'm missing here? The dxf is empty when I attempt the export.

    import processing.dxf.*; 
    
    Table dotdata;
    String filepath="";
    String savefilepath="";
    int columncount= 0;
    int rowcount=0;
    
    float xtranslate=150;
    float ytranslate=-150;
    
    PShape texturePoints;
    
    void setup() {
      size(500, 500,P2D);
      background(0);
      texturePoints = createShape();
      dotdata=new Table();
      selectInput("Select .txt file", "fileSelected");
      beginRaw(DXF, "test.dxf");
    }
    
    void draw() {
      if (!filepath.equals("")) {
    
        dotdata = loadTable(filepath, "tsv");
    
        for (int i=0; i<7; i++) {
          dotdata.removeRow(0);
        }
        dotdata.removeColumn(5);
        dotdata.removeColumn(4);
        dotdata.removeColumn(1);
        dotdata.removeColumn(0);
    
        dotdata.addColumn();
        dotdata.addColumn();
        dotdata.addColumn();
    
        //int columncount= dotdata.getColumnCount();
        int rowcount=dotdata.getRowCount();
    
    
        texturePoints.beginShape(POINTS);
        for (int i=0; i<rowcount; i++) {
          dotdata.setFloat(i, 2, dotdata.getFloat(i, 0)+xtranslate);
          dotdata.setFloat(i, 3, dotdata.getFloat(i, 1)+ytranslate);
    
          texturePoints.vertex(dotdata.getFloat(i, 0)+xtranslate, dotdata.getFloat(i, 1)+ytranslate);
        }
        texturePoints.endShape();
        endRaw();
    
        for (int i=0; i<rowcount; i++) {
          dotdata.setString(i, 4, str(dotdata.getFloat(i, 2)) + "," + str(dotdata.getFloat(i, 3)));
        }
    
        filepathnaming();
    
        saveTable(dotdata, savefilepath);
        exit();
      }
    }
    
    
    
    void fileSelected(File selection) {
      if (selection == null) {
        println("Window was closed or the user hit cancel.");
        exit();
      } else {
        filepath=selection.getAbsolutePath();
      }
    }
    
    void filepathnaming() {
      savefilepath="";
      String[] filepathlist = split(filepath, "\\");
    
      for (int i=0; i<filepathlist.length-1; i++) {
        savefilepath +=filepathlist[i]+ "\\";
      }
    
      savefilepath += filepathlist[filepathlist.length-1].substring(0, filepathlist[filepathlist.length-1].indexOf(".txt"))+"_update.csv";
    
      println(savefilepath);
    }
    
  • Go back edit your post

    format your code better

  • can you provide a sample tsv file, just a short one...

    the library still doesn't support POINTS, i was just pointing out to jeremy that the limitation wasn't PShape, even though the reference suggests that PShape doesn't do points.

    did you see an error when you ran your code?

  • edited July 2017

    @koogs @jeremydouglass I did not see any error code when running the code.

    Please see the sample data below.

    Header              
    Header                  
    Header                  
    Header
    Header
    
    Header                  
    22  22  0.00936134  0.05347252  22  22
    22  22  -0.05231157 0.16031957  22  22
    22  22  0.07103424  0.16031957  22  22
    22  22  -0.11398447 0.26716662  22  22
    22  22  0.00936134  0.26716662  22  22
    22  22  0.13270714  0.26716662  22  22
    22  22  0.25605295  0.26716662  22  22
    22  22  -0.29900318 0.37401366  22  22
    22  22  -0.17565737 0.37401366  22  22
    22  22  -0.05231157 0.37401366  22  22
    22  22  0.07103424  0.37401366  22  22
    22  22  0.19438004  0.37401366  22  22
    22  22  0.31772585  0.37401366  22  22
    22  22  -0.36067608 0.48086071  22  22
    22  22  -0.23733027 0.48086071  22  22
    22  22  -0.11398447 0.48086071  22  22
    22  22  0.00936134  0.48086071  22  22
    22  22  0.13270714  0.48086071  22  22
    22  22  0.25605295  0.48086071  22  22
    22  22  0.37939875  0.48086071  22  22
    22  22  0.50274456  0.48086071  22  22
    22  22  -0.42234898 0.58770775  22  22
    22  22  -0.29900318 0.58770775  22  22
    22  22  -0.17565737 0.58770775  22  22
    22  22  -0.05231157 0.58770775  22  22
    22  22  0.07103424  0.58770775  22  22
    22  22  0.19438004  0.58770775  22  22
    22  22  0.31772585  0.58770775  22  22
    22  22  0.44107165  0.58770775  22  22
    22  22  0.56441746  0.58770775  22  22
    22  22  -0.48402188 0.6945548   22  22
    22  22  -0.36067608 0.6945548   22  22
    22  22  -0.23733027 0.6945548   22  22
    22  22  -0.11398447 0.6945548   22  22
    22  22  0.00936134  0.6945548   22  22
    22  22  0.13270714  0.6945548   22  22
    22  22  0.25605295  0.6945548   22  22
    
  • @koogs Hey Koogs. Any update on whether the library could be updated to allow support for plotting points to a dxf?

Sign In or Register to comment.