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();
}
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.
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.
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.