Cannot Export DXF from PWindow?

Hallo.

I have the following problem.
In a second window of my sketch that i use for previewing in 3d, i have a set of pshapes drawn in 3d space, but i cannot get them to be exported as dxf. Actually, nothing is exported, no file is made. What am i missing? (the main window is P2D but the export commands are in this PWindow with p3d renderer)
And Secondly will i be able to use it in cad software? e.g. fusion 360?

import processing.dxf.*;
boolean record = false;
PWindow win;
import peasy.PeasyCam;
PeasyCam cam;



class PWindow extends PApplet {
  PWindow() {
    super();
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
  }

  void settings() {
    size(600,600, P3D);
  }

  void setup() {
    background(150);
    cam = new PeasyCam(this, 1400); //400 == zoom
  }

PShape feta;
  void draw() {
    background(100); 
    lights();

    if (record == true) {
      println("started dxf");
      beginRaw(DXF, "output.dxf"); // Start recording to the file
    }

    for (int i=0; i<shapesPreview.size(); i++) {
      feta = createShape();
      feta.beginShape();
      for (int j=0; j<shapesPreview.get(i).size(); j++) {
        if (withCurves) {
          feta.curveVertex(shapesPreview.get(i).get(j).x, shapesPreview.get(i).get(j).y);
        } else {
          feta.vertex(shapesPreview.get(i).get(j).x, shapesPreview.get(i).get(j).y);
        }
        if (j== shapesPreview.get(i).size()-1) {
          feta.vertex(shapesPreview.get(i).get(j).x, (i+1)*tileH);
          feta.vertex(0, (i+1)*tileH );
          feta.vertex(shapesPreview.get(i).get(0).x, shapesPreview.get(i).get(0).y );
        }
      }
      feta.endShape(CLOSE);

      pushMatrix();
      translate(0, -i*tileH, i*tileH); 
      shape(feta, 0, 0);
      popMatrix();
    }
   
    if (record == true) {
      println("ended dxf");
      endRaw();
      record = false; // Stop recording to the file
    }

  }


  void keyPressed() {
    if (key=='1') record=true;
    if (key=='3') {
      shapesPreview = new ArrayList<ArrayList<PVector>>();
      shapesPreview = shapes;
    }
  }
}

Check out these 2 examples about using runSketch() + ARGS_SKETCH_FOLDER + sketchPath():

1 Like

Thank you!!!
so it was actually exported but somewhere else. I did test it by “C:/output.dxf” and did worked but the same file exported to svg takes about 37KB and on .dxf 7.5MB is normal?

Dunno anything about .dxf. .svg is just a human readable file w/ coordinates.

1 Like