DXF Export headache
in
Contributed Library Questions
•
2 years ago
Hi everyone, I am having a few problems replicating a fantastic example of a DXF Export. I've included 2 lots of code below, the first being the original example, the second being a copy of the code I have tried to implement it into. The problem regards exporting a complex 3d shape. The first example builds a complex shape with a for loop and is able to export the shape as a whole. I have tried to do this in the second example but just end up being able to export one single instance of box and not the whole shape as it appears on my screen, i.e several boxes of varying heights in a line. Here is a screen shot of the output of processing with the resulting DXF export:
Notice how the Processing output (on the left) is made of loads of boxes and the DFX output, when opened in another program (Solidworks eDrawing), is reduced to just a single instance of a box. The original example code, listed first below, works fine in both programs.
Any help would be appreciated!
- import peasy.*;
- import processing.dxf.*;
- /*-------------------------------------------------------
- *** GLOBAL VARIABLES ***
- --------------------------------------------------------*/
- // Variable to store boolean 'export' toggle
- boolean dxfExport;
- PeasyCam theCamera;
- float BBOX = 400;
- /*-------------------------------------------------------
- *** GLOBAL SETUP ***
- --------------------------------------------------------*/
- void setup() {
- //--------------------- general things
- size(600, 600, P3D);
- background(0);
- theCamera = new PeasyCam(this, 2*BBOX);
- theCamera.lookAt(BBOX/2,BBOX/2,BBOX/2);
- }
- /*-------------------------------------------------------
- *** GLOBAL SETUP ***
- --------------------------------------------------------*/
- void draw() {
- //--------------------- general things
- background(0);
- lights();
- //--------------------- if export is TRUE
- if (dxfExport) {
- beginRaw(DXF, "output.dxf");
- }
- //--------------------- do all your drawing here
- stroke(120);
- fill(120);
- pushMatrix();
- for(int i = 0; i < 100; ++i) {
- translate(BBOX/2,BBOX/2,BBOX/2);
- rotateX(i*5);
- rotateY(i*7);
- rotateZ(i*12);
- box (BBOX +(5*i) );
- }
- popMatrix();
- //--------------------- finish export and set dxfExport to FALSE
- if(dxfExport) {
- endRaw();
- dxfExport = false;
- }
- }
- /*-------------------------------------------------------
- *** GLOBAL KEYSTOKE EVENTS ***
- --------------------------------------------------------*/
- void keyPressed() {
- // use a key press so that it doesn't make a million files
- switch (key) {
- case 'x':
- dxfExport = true;
- println("DXF export complete!");
- break;
- case 's':
- saveFrame("boxes.jpg");
- println("screen grab made");
- break;
- }
- }
Here's my code:
- import krister.Ess.*;
- import peasy.*;
- import processing.dxf.*;
- //---------------------------------------------------------//Declare Array
- ArrayList myArrayList;
- AudioChannel myChannel;
- FFT myFFT;
- int d=30;
- int bufferSize=256;
- boolean writeToArray;
- boolean drawFromArray;
- boolean dxfExport;
- PeasyCam theCamera;
- float BBOX = 400;
- void setup() {
- size(1000,500,P3D);
- background(0);
- theCamera = new PeasyCam(this, 2*BBOX);
- theCamera.lookAt(BBOX/2,BBOX/2,BBOX/2);
- Ess.start(this); // start up Ess
- //--------------------------------------------------------//Create Array
- myArrayList = new ArrayList();
- //--------------------------------------------------------//Setup FFT
- myChannel=new AudioChannel("cell.aif");// load "cell.aif" into a new AudioChannel
- myFFT=new FFT(bufferSize*2); // set FFT size
- myFFT.damp(.1); // damp our spectrum data
- myChannel.play(1); // start the sound looping once
- fill(#B2B0B0);
- }
- void draw() {
- lights();
- background (0);
- //--------------------- if export is TRUE
- if (dxfExport) {
- beginRaw(DXF, "output.dxf");
- }
- //------------------------------------------------------------------------------------------------------------//If 'W/w" is pressed, write to array
- if(keyPressed) {
- if (key == 'w' || key == 'W') {
- writeToArray = true;}
- } else {
- writeToArray = false;}
- if(writeToArray){
- //-------------------------------------------------------//get our spectrum data
- myFFT.getSpectrum(myChannel);
- //-------------------------------------------------------//write values to our ArrayList
- myArrayList.add(myFFT.spectrum[1]);
- }
- //------------------------------------------------------------------------------------------------------------//Draw from array
- for(int i = 0; i < myArrayList.size(); i++){
- //-------------------------------------------------------//map each number from the array to a useful range
- float x = map((Float)myArrayList.get(i), 0.0, 0.05, 0, 100);
- //-------------------------------------------------------//draw something
- pushMatrix();
- translate(i*5, height/2, i*2-500);
- box(5, x, 5);
- popMatrix();
- //-------------------------------------------------------//finish export and set dxfExport to FALSE
- if(dxfExport) {
- endRaw();
- dxfExport = false;
- }
- }
- }
- void keyPressed() {
- // use a key press so that it doesn't make a million files
- switch (key) {
- case 'x':
- dxfExport = true;
- println("DXF export complete!");
- break;
- case 's':
- saveFrame("boxes.jpg");
- println("screen grab made");
- break;
- }
- }
- //-------------------------------------------------------//we are done, clean up Ess
- public void stop() {
- Ess.stop();
- super.stop();
- }
1