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

**URL:** https://discourse.processing.org/t/turn-x-y-z-mouse-tracker-into-3d-cad-file/12275
**Category:** Coding Questions
**Created:** [June 24, 2019, 9:00pm UTC](https://discourse.processing.org/t/turn-x-y-z-mouse-tracker-into-3d-cad-file/12275 "2019-06-24T21:00:59Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![sdotjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sdotjo/32/5639_2.png) [@sdotjo](https://discourse.processing.org/u/sdotjo)
#### Post date: [June 24, 2019, 9:01pm UTC](https://discourse.processing.org/t/turn-x-y-z-mouse-tracker-into-3d-cad-file/12275/1 "2019-06-24T21:01:00Z")

</div>

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:

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

```

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [June 24, 2019, 10:50pm UTC](https://discourse.processing.org/t/turn-x-y-z-mouse-tracker-into-3d-cad-file/12275/2 "2019-06-24T22:50:07Z")

</div>

Hey,

Welcome on the forum 🙂  
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 :

- [https://funprogramming.org/152-Exporting-3D-shapes-as-obj-files-in-Processing.html](https://funprogramming.org/152-Exporting-3D-shapes-as-obj-files-in-Processing.html)

And also 3d libraries :

- [https://processing.org/reference/libraries/#3d](https://processing.org/reference/libraries/#3d)

---

<div class="post-metadata">

### Author: ![sdotjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sdotjo/32/5639_2.png) [@sdotjo](https://discourse.processing.org/u/sdotjo)
#### Post date: [June 24, 2019, 11:03pm UTC](https://discourse.processing.org/t/turn-x-y-z-mouse-tracker-into-3d-cad-file/12275/3 "2019-06-24T23:03:52Z")

</div>

Thank you! Reformatted the code as you say. 🙏

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.

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [June 24, 2019, 11:26pm UTC](https://discourse.processing.org/t/turn-x-y-z-mouse-tracker-into-3d-cad-file/12275/4 "2019-06-24T23:26:30Z")

</div>

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 :

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

```

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

- [https://developer.rhino3d.com/guides/rhinopython/what-is-rhinopython/](https://developer.rhino3d.com/guides/rhinopython/what-is-rhinopython/)
- [https://developer.rhino3d.com/guides/rhinopython/python-rhinoscriptsyntax-line/](https://developer.rhino3d.com/guides/rhinopython/python-rhinoscriptsyntax-line/)

---

<div class="post-metadata">

### Author: ![sdotjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sdotjo/32/5639_2.png) [@sdotjo](https://discourse.processing.org/u/sdotjo)
#### Post date: [June 24, 2019, 11:43pm UTC](https://discourse.processing.org/t/turn-x-y-z-mouse-tracker-into-3d-cad-file/12275/5 "2019-06-24T23:43:13Z")

</div>

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

---

<div class="post-metadata">

### Author: ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)
#### Post date: [June 25, 2019, 5:51pm UTC](https://discourse.processing.org/t/turn-x-y-z-mouse-tracker-into-3d-cad-file/12275/6 "2019-06-25T17:51:43Z")

</div>

Hi @sdotjo,

I think you can directly send the output of your Processing sketch to Rhino via the [gHowl](https://www.grasshopper3d.com/group/ghowl) Grasshopper component. The various video examples/tutorials posted on YT and vimeo could probably help.

---

<div class="post-metadata">

### Author: ![sdotjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sdotjo/32/5639_2.png) [@sdotjo](https://discourse.processing.org/u/sdotjo)
#### Post date: [June 25, 2019, 6:02pm UTC](https://discourse.processing.org/t/turn-x-y-z-mouse-tracker-into-3d-cad-file/12275/7 "2019-06-25T18:02:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![sdotjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sdotjo/32/5639_2.png) [@sdotjo](https://discourse.processing.org/u/sdotjo)
#### Post date: [June 25, 2019, 6:05pm UTC](https://discourse.processing.org/t/turn-x-y-z-mouse-tracker-into-3d-cad-file/12275/8 "2019-06-25T18:05:23Z")

</div>

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

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

```

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

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [June 25, 2019, 8:45pm UTC](https://discourse.processing.org/t/turn-x-y-z-mouse-tracker-into-3d-cad-file/12275/9 "2019-06-25T20:45:44Z")

</div>

```auto

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

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

```

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [June 26, 2019, 10:54am UTC](https://discourse.processing.org/t/turn-x-y-z-mouse-tracker-into-3d-cad-file/12275/10 "2019-06-26T10:54:52Z")

</div>

Simply use :

```auto
output.println(mouseX+","+mouseY+","+z);

```

---

<div class="post-metadata">

### Author: ![sdotjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sdotjo/32/5639_2.png) [@sdotjo](https://discourse.processing.org/u/sdotjo)
#### Post date: [June 26, 2019, 1:18pm UTC](https://discourse.processing.org/t/turn-x-y-z-mouse-tracker-into-3d-cad-file/12275/11 "2019-06-26T13:18:14Z")

</div>

That’s it! Thank you 🙏🙏
