OpenSCAD surface Gimp Export Plugin

by ffaat, published

OpenSCAD surface Gimp Export Plugin by ffaat Nov 22, 2012


I've written a gimp python plugin to export the openscad surface format. The pic shows the greyscale height-field and the resultant openscad surface.
This was done to design terrain in gimp and send the tiles to a 3d printer.

Recent Comments

view all
Glad you figured out out!
Nope, i take it back. I just forgot to chmod +x file.py to make it work :D
Same issue for me, maybe only works on older gimp?

More from 3D Printing

view more

Liked By

view all

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag. Print Thing Tag


Extract the python file an put it in your gimp plugin directory.
Open a greyscale image in gimp then save it with a ".dat" extension (i.e. "testsurface.dat"

Then use this in openscad comme ca:

surface(file = "testsurface.dat", center=true, convexity = 5);

and scale as needed...

Note that really large surface files will cause openSCAD to die horribly, so it is best to prescale the image before exporting.

I've adjusted the scaling so the 0->255 will map to exactly -0.5 -> 0.5.
Note that the surface routine seems to add a 1 unit high base to the imported surface, so the actual surface rendered will be from -1.5 -> 0.5, so you need to intersect it with a 1 unit high centered box to trim off this base.

Also not that the surface import function does NOT create steps - it generates the triangles vertices based on the pixel values.

This means for a 4x4 image that is a B&W 2x2 checkboard you end up with:
0.5 0.5 -0.5 -0.5
0.5 0.5 -0.5 -0.5
-0.5 -0.5 0.5 0.5
-0.5 -0.5 0.5 0.5

which renders 3x3 units x by y. consisting of two tableaus at -0.5 and two tableaus at 0.5 with sloped surfaces between (which might not be what you were expecting). One of the example images shows this.
Having a little trouble. All values are -0.5 Have the latest Gimp and Python installed.
Note that this plugin scales values from -0.5 to 0.5 (or just under*) which might not be what you are expecting (but is not wrong). Also, it looks like openscad itself adds some kind of raft to the surface. The manual doesn't have much detail on this but something else to be borne in mind.

*Changing the calculation to (pixval-127.5)/255 would produce what one might be expecting.
Is there a way back? Using a stl-file to generate a grayscale hight map png-file?
The simplest way is to take the stl into a 3d rendering program and colour it with a black to white gradient along the Z axis. Then set up the camera directly above the surface with a non-perspective projection and render an image at the scale you want.
Thank you for the Plug-In. I tested it with Gimp 2.8.3 (OS X 10.8.3), it works.

How-to for use with Customizable Lithopane offline:

First extract the python file "http://openscad_surface_export.py" and put it in your gimp plugin folder (/Application/Gimp/Content/Resources/lib/glimp/2.0/plug-ins)

1. Open an image in Gimp.
2. Select <img> (right mouse click) Image -> Mode -> Grayscale.
3. Invert Colors: Menu > Colors > Invert.
4. Export the image with a ".dat" extension (i.e. "Surface.dat").

However it doesn't work with the latest Gimp-Version 2.8.4.
Can you be more specific other than "it doesn't work"? Are there any errors, does the file get created incorrectly, or nothing at all?
I installed the new Version 2.8.4 and the plug-in again. Now it works.
Last time the export (Menu: File>Export>"Surface.dat") failed. I got this message:
"The given filename does not have any known file extension..."

Sorry for the mistake!
Hi, I tested your plugin with Gimp 2.8.x in Linux, it doesn't work maybe with the new politic of the Saving menu (only Gimp file here).
For the newer version of GIMP, you need to use the export command, then select the .dat extension. Works great for me now. A bit of a learning curve to get it working. Awesome plugin!
Thanks Pyrophreek for your reply but it doesn't work for me.
If I force the export with the .dat extension, I get this message:
"The given filename does not have any known file extension. Please enter a known file extension or select a file format from the file format list."
The plugin is installed in the home user folder of Gimp plug-ins. (~/.gimp-2.8/plug-ins/).
I put it in C:Program FilesGIMP 2libgimp2.0plug-ins (windows). Haven't tried it in the other directories.
thanks for your reply.

I've just tried to put the plugin in the main folder /usr/lib/gimp/2.0/plug-ins/ but it doesn't work. The ".dat" extension is not available in the export menu.
May be, it's a problem with the linux version.
Same issue for me, maybe only works on older gimp?
Nope, i take it back. I just forgot to chmod +x file.py to make it work :D
Glad you figured out out!