<p>I would suggest using OpenSCAD for this. OpenSCAD does not natively support reading data files that aren't 3D/2D models or images, but you can write a simple program to generate OpenSCAD code.</p>

<p>I would suggest first writing an OpenSCAD file that implements your chosen type of "ball" and "stick", perhaps like:</p>

<pre><code>module ball(x, y, z) {
    translate([x, y, z]) 
        sphere(d=10, <span class="math-container">$fn=60);
}
module stick(x, y, z, length, rx, ry, rz) {
    translate([x, y, z]) 
    rotate([rx, ry, rz]) 
        cylinder(d=5, length=length, $</span>fn=60, center=true);
}
</code></pre>

<p>Then, take your data file — let's suppose it's a CSV —</p>

<pre><code>ball,0,0,0
ball,100,0,0
stick,50,0,0,100,0,90,0
</code></pre>

<p>and convert it into OpenSCAD by adding the appropriate syntax (this could even be done using a basic find-and-replace tool):</p>

<pre><code>import &lt;ball-and-stick-definitions.scad&gt;
ball(0,0,0);
ball(100,0,0);
stick(50,0,0,100,0,90,0);
</code></pre>

<p>Then, producing the STL is just a matter of running the <code>openscad</code> command on your generated OpenSCAD source code.</p>

<p>If your stick parameters are not Euler angles but "start point" and "end point" you'll have to add the "rotate to point at…" math yourself, but that is within OpenSCAD's capabilities as it has vector math operations and <code>multmatrix</code>, or trigonometry if you prefer to generate Euler angles; you don't need to do that math at the file-conversion stage.</p>

CC BY-SA 4.0
2019-12-02T20:05:36.880Z
2019-12-02T20:05:36.880Z
Kevin Reid
<p>I regularly have 3D models that consist of a Boolean union of balls and cylinders (molecule models, star maps, mathematical designs), that I then want to convert to a STL model for printing at Shapeways. But I don't know how to easily do that! I already have the model as a series of floating point numbers (four for each ball, and seven for each cylinder), so I don't want to have to go into a graphical interface to click/drag points. Instead I want to convert my lists of floating point numbers to STL from the command line.</p>

<p>I thought this would be a trivial thing, but I cannot find what is the best tool for this. All I need, I think, is a pointer to what tools are most appropriate (although more detailed help will be appreciated :-)) I thought that "gmsh" might be good for this, but it is not immediately clear to me how to use it for that.</p>

<p>I would like the software for this to be "free", in the sense that it does not cost money. Also, I am not a Windows user, so I would like to be able to run this under Linux or macOS.</p>

CC BY-SA 4.0
2019-12-02T11:16:29.587Z
Being naive, I asked this on the graphics design stackexchange, and was told to take it here.
Freek Wiedijk
CC BY-SA 4.0
2019-12-02T11:47:24.150Z
Maybe probably perhaps OpenSCAD could use those points of yours.
towe
CC BY-SA 4.0
2019-12-02T14:12:16.273Z
That was the answer on the graphics design stackexchange: https://graphicdesign.stackexchange.com/questions/131653/convert-ball-stick-model-to-stl-from-the-command-line
Freek Wiedijk
CC BY-SA 4.0
2019-12-02T21:05:52.677Z
I appreciate the upvote on the GD SE. If you find it acceptable, please click the check mark on that SE. Kevin Reid provided a good answer here and should also receive an upvote and an acceptance. I see no need to post my previously created answer here, especially as you've linked to it via the comment.
fred_dot_u
<3d-models><3d-design>
Convert ball-stick model to STL from the command line
Freek Wiedijk
# Convert ball-stick model to STL from the command line

(Asked by: username_0 on 2019-12-02)

I regularly have 3D models that consist of a Boolean union of balls and cylinders (molecule models, star maps, mathematical designs), that I then want to convert to a STL model for printing at Shapeways. But I don't know how to easily do that! I already have the model as a series of floating point numbers (four for each ball, and seven for each cylinder), so I don't want to have to go into a graphical interface to click/drag points. Instead I want to convert my lists of floating point numbers to STL from the command line.

I thought this would be a trivial thing, but I cannot find what is the best tool for this. All I need, I think, is a pointer to what tools are most appropriate (although more detailed help will be appreciated :-)) I thought that "gmsh" might be good for this, but it is not immediately clear to me how to use it for that.

I would like the software for this to be "free", in the sense that it does not cost money. Also, I am not a Windows user, so I would like to be able to run this under Linux or macOS.

**Tags:** 3d-models, 3d-design

> **Comments:**
> **username_0**: Being naive, I asked this on the graphics design stackexchange, and was told to take it here.  
> **username_1**: Maybe probably perhaps OpenSCAD could use those points of yours.  
> **username_0**: That was the answer on the graphics design stackexchange: https://graphicdesign.stackexchange.com/questions/131653/convert-ball-stick-model-to-stl-from-the-command-line  
> **username_2**: I appreciate the upvote on the GD SE. If you find it acceptable, please click the check mark on that SE. username_3 provided a good answer here and should also receive an upvote and an acceptance. I see no need to post my previously created answer here, especially as you've linked to it via the comment.  

---

## 1 answers

### Answer by username_3 on 2019-12-02. Score: 4 | Accepted answer

I would suggest using OpenSCAD for this. OpenSCAD does not natively support reading data files that aren't 3D/2D models or images, but you can write a simple program to generate OpenSCAD code.

I would suggest first writing an OpenSCAD file that implements your chosen type of "ball" and "stick", perhaps like:

```
module ball(x, y, z) {
    translate([x, y, z]) 
        sphere(d=10, $fn=60);
}
module stick(x, y, z, length, rx, ry, rz) {
    translate([x, y, z]) 
    rotate([rx, ry, rz]) 
        cylinder(d=5, length=length, $fn=60, center=true);
}

```

Then, take your data file — let's suppose it's a CSV —

```
ball,0,0,0
ball,100,0,0
stick,50,0,0,100,0,90,0

```

and convert it into OpenSCAD by adding the appropriate syntax (this could even be done using a basic find-and-replace tool):

```
import <ball-and-stick-definitions.scad>
ball(0,0,0);
ball(100,0,0);
stick(50,0,0,100,0,90,0);

```

Then, producing the STL is just a matter of running the `openscad` command on your generated OpenSCAD source code.

If your stick parameters are not Euler angles but "start point" and "end point" you'll have to add the "rotate to point at…" math yourself, but that is within OpenSCAD's capabilities as it has vector math operations and `multmatrix`, or trigonometry if you prefer to generate Euler angles; you don't need to do that math at the file-conversion stage.


---

