Turn X,Y, Z mouse tracker into 3D CAD file?

Hello!

I am working on a project to be able to “draw” with a 3D clay printer. Right now I have a sketch that draws X,Y with mouse movement and Z with time elapsed.

I want to be able to export this line as a CAD file so that I can view the line in Rhino CAD software.

Is that possible?

Here’s my sketch so far:

PrintWriter output;

int count = 0;
int x = 0;
int y = 0;
int i=0;
int timer = 0;
float m;

ArrayList xp = new ArrayList();
ArrayList yp = new ArrayList();

void setup(){
  output = createWriter("coordinates.txt");
  size(1240,800, P3D); 
  background(0);  
  noFill();
  stroke(255);
  strokeWeight(1);
  
}

void draw(){
  background(0);
  
  int sx,ex,sy,ey;
  float z = 0;
  xp.add(mouseX);
  yp.add(mouseY); 
  if(xp.size() > 1){
    for(int i = xp.size()-1 ; i > 0 ; i--){
  sx = (Integer) xp.get(i);
  ex = (Integer) xp.get(i-1);
  sy = (Integer) yp.get(i);
  ey = (Integer) yp.get(i-1);
  line(sx,sy,z,ex,ey,z-1);
  z -= 1;
}
 
    output.println ("x=" + mouseX);
    output.println ("y=" + mouseY);
    output.println ("z=" + z);
  } 
}
 void keyPressed(){ 
    output.flush();
    output.close();
    exit();
  }
1 Like

Hey,

Welcome on the forum :slight_smile:
To format your code you can press Ctrl+T in the Processing IDE then use the </> button in the message editor on the forum.

This link might help you :

And also 3d libraries :

1 Like

Thank you! Reformatted the code as you say. :pray:

It seems from what I’ve seen so far that the 3D libraries aren’t the way to go for me because I don’t want my sketch to result in a mesh, but instead to remain a single line. This line will eventually be translated to gcode. This won’t follow a conventional shape>slicer>gcode workflow but rather line>gcode.

One solution might be :

To write a Python script in Rhino because I used to do it and it’s not complicated if you use your coordinate.txt file.
If you write each x,y,z coordinates in your text file like this :

x1,y1,z1
x2,y2,z2
...

Then you can easily extract them and get a line (or curve) in Rhino.

1 Like

Awesome! I’ll give that a try. Thank you!! :grin:

Hi @sdotjo,

I think you can directly send the output of your Processing sketch to Rhino via the gHowl Grasshopper component. The various video examples/tutorials posted on YT and vimeo could probably help.

1 Like

Oh nice! That sounds promising, I’ll take a look. Thank you!

Do you have any tips for formatting the text as you showed? ie:

x1,y1,z1
x2,y2,z2
...

I’m stuck on how to output in that format.



for (int i = xp.size()-1; i > 0; i--) {
  sx = (Integer) xp.get(i);
  sy = (Integer) yp.get(i);

  output.println (sx+","+sy);
}
2 Likes

Simply use :

output.println(mouseX+","+mouseY+","+z);
2 Likes

That’s it! Thank you :pray::pray:

1 Like