OpenSCAD User Manual/STL Import and Export - Wikibooks, open books for an open world (2024)

Contents

  • 1 Import Modules
    • 1.1 import
      • 1.1.1 Parameters
        • 1.1.1.1 Convexity
        • 1.1.1.2 Notes
        • 1.1.1.3 CGAL ERROR: assertion violation!
    • 1.2 import_dxf
    • 1.3 import_stl
    • 1.4 surface
      • 1.4.1 Parameters
      • 1.4.2 Text file format
      • 1.4.3 Images
      • 1.4.4 Examples
  • 2 Export Commands
    • 2.1 Export
    • 2.2 STL Export

A prime ingredient of any 3D design flow is the ability to import from and export to other tools. The STL file format is currently the most common format used.

[edit | edit source]

OpenSCAD User Manual/STL Import and Export - Wikibooks, open books for an open world (1)

The text in its current form is incomplete.

Importing is achieved by the import() command.

[Note: Requires version 2015.03-2] The File >> Open command may be used to insert this command. The file type filter of the Open File dialog may show only OpenSCAD files, but file name can be replaced with a wildcard (e.g. *.stl) to browse to additional file types.

import

[edit | edit source]

Imports a file for use in the current OpenSCAD model. The file extension is used to determine which type.

3D formats
  • STL (both ASCII and Binary)
  • OFF
  • AMF [Note: Requires version 2019.05]
  • 3MF [Note: Requires version 2019.05]
2D formats
  • DXF
  • SVG [Note: Requires version 2019.05]
Other
  • CSV [Note: Requires version Development snapshot]
  • CSG can be imported using include<> or loaded like an SCAD file
  • PNG can be imported using surface()

Parameters

[edit | edit source]

<file>
A string containing the path to file.:If the give path is not absolute, it is resolved relative to the importing script. Note that when using include<> with a script that uses import(), this is relative to the script doing the include<>.
<convexity>
An Integer. The convexity parameter specifies the maximum number of front sides (or back sides) a ray intersecting the object might penetrate. This parameter is needed only for correctly displaying the object in OpenCSG preview mode and has no effect on the polyhedron rendering. Optional.
<layer>
For DXF import only, specify a specific layer to import. Optional.
$fn
Double. The number of polygon segments to use when converting circles, arcs, and curves to polygons. [Note: Requires version Development snapshot]
$fa
Double. The minimum angle step to use when converting circles and arcs to polygons. [Note: Requires version Development snapshot]
$fs
Double. The minimum segment length to use when converting circles and arcs to polygons. [Note: Requires version Development snapshot]
id
String. For SVG import only, the id of an element or group to import. Optional. Also supports Inkscape layer names. [Note: Requires version Development snapshot]
import("example012.stl", convexity=3);import("D:/Documents and Settings/User/My Documents/Gear.stl", convexity=3);(Windows users must "escape" the backslashes by writing them doubled, or replace the backslashes with forward slashes.)

Read a layer of a 2D DXF file and create a 3D shape.

linear_extrude(height = 5, center = true, convexity = 10)import_dxf(file = "example009.dxf", layer = "plate");

Convexity

[edit | edit source]

This image shows a 2D shape with a convexity of 2, as the ray indicated in red intersects with the 2D shape in at most two sections. The convexity of a 3D shape would be determined in a similar way. Setting it to 10 should work fine for most cases.

Notes

[edit | edit source]

In the latest version of OpenSCAD, import() is now used for importing both 2D (DXF for extrusion) and 3D (STL) files.

CGAL ERROR: assertion violation!

[edit | edit source]

If you want to render the imported STL file later, you have to make sure that the STL file is "clean". This means that the mesh has to be manifold and should not contain holes nor self-intersections. If the STL is not clean, it might initially import and preview fine, but then as soon as you attempt to perform computational geometry on it by rendering a combination of it with something else, you might get warnings about it not being manifold, your imported stl might disappear from the output entirely, or you might get errors like:

 CGAL error in CGAL_Build_PolySet: CGAL ERROR: assertion violation! Expr: check_protocoll == 0 File: /home/don/openscad_deps/mxe/usr/i686-pc-mingw32/include/CGAL/Polyhedron_incremental_builder_3.h Line: 199

or

 CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation! Expr: pe_prev->is_border() || !internal::Plane_constructor<Plane>::get_plane(pe_prev->facet(),pe_prev->facet()->plane()).is_degenerate() File: /home/don/openscad_deps/mxe/usr/i686-pc-mingw32/include/CGAL/Nef_3/polyhedron_3_to_nef_3.h Line: 253

In order to clean the STL file, you have the following options:

  • use http://wiki.netfabb.com/Semi-Automatic_Repair_Options to repair the holes but not the self-intersections.
  • use netfabb basic. This free software doesn't have the option to close holes nor can it fix the self-intersections.
  • use MeshLab, This free software can fix all the issues.

Using MeshLab, you can do:

  • Render - Show non Manif Edges
  • Render - Show non Manif Vertices
  • if found, use Filters - Selection - Select non Manifold Edges or Select non Manifold Vertices - Apply - Close. Then click button 'Delete the current set of selected vertices...' or check http://www.youtube.com/watch?v=oDx0Tgy0UHo for an instruction video. The screen should show "0 non manifold edges", "0 non manifold vertices"


Next, you can click the icon 'Fill Hole', select all the holes and click Fill and then Accept. You might have to redo this action a few times.

Use File - Export Mesh to save the STL.


If Meshlab can't fill the last hole then Blender might help:

  1. Start Blender
  2. `X, 1` to remove the default object
  3. File, Import, Stl
  4. `Tab` to edit the mesh
  5. `A` to de-select all vertices
  6. `Alt+Ctrl+Shift+M` to select all non-manifold vertices
  7. `MMB` to rotate, `Shift+MMB` to pan, `wheel` to zoom
  8. `C` for "circle" select, `Esc` to finish
  9. `Alt+M, 1` to merge or `Space` and search for "merge" as alternative
  10. Merging vertices is a useful way of filling holes where the vertices are so closely packed that the slight change in geometry is unimportant compared to the precision of a typical 3D printer

import_dxf

[edit | edit source]

[Deprecated: import_dxf() will be removed in future releases.Use import() instead.]

Read a DXF file and create a 3D shape.

linear_extrude(height = 5, center = true, convexity = 10)import_dxf(file = "example009.dxf", layer = "plate");

import_stl

[edit | edit source]

[Deprecated: import_stl() will be removed in future releases.Use import() instead. See above.]

Imports an STL file for use in the current OpenSCAD model

import_stl("body.stl", convexity = 5);

surface

[edit | edit source]

surface() reads Heightmap information from text or image files.It can read PNG files.

Parameters

[edit | edit source]

file
String. The path to the file containing the heightmap data.
center
Boolean. This determines the positioning of the generated object. If true, object is centered in X- and Y-axis. Otherwise, the object is placed in the positive quadrant. Defaults to false.
invert
Boolean. Inverts how the color values of imported images are translated into height values. This has no effect when importing text data files. Defaults to false. [Note: Requires version 2015.03]
convexity
Integer. The convexity parameter specifies the maximum number of front sides (back sides) a ray intersecting the object might penetrate. This parameter is needed only for correct display of the object in OpenCSG preview mode and has no effect on the final rendering.

Text file format

[edit | edit source]

The format for text based heightmaps is a matrix of numbers that represent the height for a specific point. Rows are mapped to the Y-axis, columns to the X axis.The numbers must be separated by spaces or tabs. Empty lines and lines starting with a # character are ignored.

Images

[edit | edit source]

[Note: Requires version 2015.03]

Currently only PNG images are supported. Alpha channel information of the image is ignored and the height for the pixel is determined by converting the color value to Grayscale using the linear luminance for the sRGB color space (Y = 0.2126R + 0.7152G + 0.0722B). The gray scale values are scaled to be in the range 0 to 100.

Examples

[edit | edit source]

Example 1:

//surface.scadsurface(file = "surface.dat", center = true, convexity = 5);%translate([0,0,5])cube([10,10,10], center =true);
#surface.dat10 9 8 7 6 5 5 5 5 5 9 8 7 6 6 4 3 2 1 0 8 7 6 6 4 3 2 1 0 07 6 6 4 3 2 1 0 0 06 6 4 3 2 1 1 0 0 06 6 3 2 1 1 1 0 0 06 6 2 1 1 1 1 0 0 06 6 1 0 0 0 0 0 0 03 1 0 0 0 0 0 0 0 03 0 0 0 0 0 0 0 0 0

Result:

Example 2

 // example010.dat generated using octave: // d = (sin(1:0.2:10)' * cos(1:0.2:10)) * 10; // save("example010.dat", "d"); intersection() { surface(file = "example010.dat", center = true, convexity = 5); rotate(45, [0, 0, 1]) surface(file = "example010.dat", center = true, convexity = 5); }

Example 3:

[Note: Requires version 2015.03]

// Example 3ascale([1, 1, 0.1]) surface(file = "smiley.png", center = true);
// Example 3bscale([1, 1, 0.1]) surface(file = "smiley.png", center = true, invert = true);

Input image

Example 3a: surface(invert = false)

Example 3b: surface(invert = true)

Example 3: Using surface() with a PNG image as heightmap input.

[edit | edit source]

OpenSCAD User Manual/STL Import and Export - Wikibooks, open books for an open world (8)

The text in its current form is incomplete.

Export

[edit | edit source]

After rendering with F6, the "File --> Export" menu can be used to export as STL, OFF, AMF, 3MF, DXF, SVG, CSG, PNG (image), or PDF.

Be sure to check the console window for error messages.

  • STL, OFF and DXF are imported using import()
  • CSG can be imported using include<> or loaded like an SCAD file
  • PNG can be imported using surface()
  • There are open pull requests for SVG and AMF, which require a bit more work/testing
  • The file suffix is used to determine type

STL Export

[edit | edit source]

To export your design, select "Export as STL..." from the "File --> Export" menu, then enter a filename in the ensuing dialog box. Don't forget to add the ".stl" extension.

Trouble shooting:

After compile and render CGAL (F6), you may see that your design is simple: no. That's bad news.

See line 8 in the following output from OpenSCAD 2010.02:

Parsing design (AST generation)...Compiling design (CSG Tree generation)...Compilation finished.Rendering Polygon Mesh using CGAL...Number of vertices currently in CGAL cache: 732Number of objects currently in CGAL cache: 12 Top level object is a 3D object: Simple: no <***************** Valid: yes Vertices: 22 Halfedges: 70 Edges: 35 Halffacets: 32 Facets: 16 Volumes: 2Total rendering time: 0 hours, 0 minutes, 0 secondsRendering finished.

When you try to export this to .STL, this message appears:

Object isn't a valid 2-manifold! Modify your design..

"Manifold" means that it is "water tight" and that there are no holes in the geometry.In a valid 2-manifold each edge must connect exactly two facets. That means that the program must be able to connect a face with an object. E.g. if you use a cube of height 10 to carve out something from a wider cube of height 10, it is not clear to which cube the top or the bottom belongs. So make the small extracting cube a bit "longer" (or "shorter"):

difference() {// originalcube (size = [2,2,2]);// object that carves out# translate ([0.5,0.5,-0.5]) { cube (size = [1,1,3]);}}

Here is a more tricky little example taken from the OpenSCAD Forum (retrieved 15:13, 22 March 2010 (UTC)):

module example1() {cube([20, 20, 20]);translate([-20, -20, 0]) cube([20, 20, 20]);cube([50, 50, 5], center = true);}module example2() {cube([20.1, 20.1, 20]);translate([-20, -20, 0]) cube([20.1, 20.1, 20]);cube([50, 50, 5], center = true);}

Example1 would render like this:

The example1 module is not a valid 2-manifold because both cubes aresharing one edge. They touch each other but do not intersect.

Example2 is a valid 2-manifold because there is an intersection. Now the construct meets the 2-manifold constraint stipulating that each edge must connect exactly two facets.

Pieces you are subtracting must extend past the original part. (OpenSCAD Tip: Manifold Space and Time, retrieved 18:40, 22 March 2010 (UTC)).

For reference, another situation that causes the design to be non-exportable is when two faces that are each the result of a subtraction touch. Then the error message comes up.

difference () { cube ([20,10,10]); translate ([10,0,0]) cube (10);}difference () { cube ([20,10,10]); cube (10);}

simply touching surfaces is correctly handled.

translate ([10,0,0]) cube (10);cube (10);
OpenSCAD User Manual/STL Import and Export - Wikibooks, open books for an open world (2024)

FAQs

Can you import STL into OpenSCAD? ›

Importing is achieved by the import() command. [Note: Requires version 2015.03-2] The File >> Open command may be used to insert this command. The file type filter of the Open File dialog may show only OpenSCAD files, but file name can be replaced with a wildcard (e.g. *. stl) to browse to additional file types.

What formats can OpenSCAD import? ›

File formats
  • 2D drawings in DXF, SVG and PNG can be imported, then extruded as monolithic parts.
  • 3D parts can be imported in STL, OFF, AMF and 3MF and can be scaled and submitted to subtractive or additive operations.

What language does OpenSCAD use? ›

OpenSCAD is written in C++, so while integration with Java is possible, it's not something I'd recommend as it's probably a fair bit of work.

Where does OpenSCAD save files? ›

Before starting a preview or render process, the OpenSCAD editor writes a backup file in case there are unsaved changes. This file is stored in the users documents folder in a separate directory (e.g. on Linux this is normally $HOME/. local/share/OpenSCAD/backups ).

Is OpenSCAD good for 3D printing? ›

OpenSCAD does not focus on creating 3D files for art projects or organic structures. It's definitely more suited for small spare parts, machine parts, and functional 3D prints. That being said, let's get started with the OpenSCAD tutorial!

What is an STL file used for? ›

STL is a file format commonly used for 3D printing and computer-aided design (CAD). The name STL is an acronym that stands for stereolithography — a popular 3D printing technology.

Which is better OpenSCAD or FreeCAD? ›

For mechanical and architectural design, FreeCAD's parametric, plugin-extensible modeling and BIM capabilities are superior. However, for precision in creating machine parts and open-source hardware, the direct control and reproducibility offered by OpenSCAD's language-based approach proves more beneficial.

Is OpenSCAD easy to learn? ›

The application is described as “the Programmers Solid 3D CAD Modeller,” but no previous programming experience is necessary. With just a little practice, even beginners can create complex shapes and animate moving parts. OpenSCAD allows very precise shapes and structures to be defined.

What can you open stl files in? ›

Here is a selection of programs allowing you to open your STL file: Microsoft 3D Viewer, FreeCAD, TinkerCAD IMSI TurboCAD Pro, CATIA, Meshlab, etc.

Why would you use OpenSCAD? ›

OpenSCAD provides two main modelling techniques: First there is constructive solid geometry (aka CSG) and second there is extrusion of 2D outlines. As data exchange format format for this 2D outlines Autocad DXF files are used.

Can FreeCAD open OpenSCAD files? ›

In FreeCAD just choose File → Open and choose the . scad file you want to import. It is not important which workbench is activated, the OpenSCAD workbench itself is only needed when applying special features to your model.

What is the Python alternative to OpenSCAD? ›

CadQuery is an intuitive, easy-to-use Python module for building parametric 3D CAD models. Using CadQuery, you can write short, simple scripts that produce high quality CAD models. It is easy to make many different objects using a single script that can be customized. CadQuery is often compared to OpenSCAD.

Does OpenSCAD use Python? ›

Python | OpenSCAD. Leverage one of the world's most popular programming languages to express parametric 3D models.

Can OpenSCAD export as a step? ›

The only way to obtain STEP from OpenSCAD that I know is an external tool that someone made. It's pretty crazy actually: it parses OpenSCAD's native export, CSG, and issues commands to OpenCASCADE's CLI, OCC-CSG.

Can OpenSCAD import SVG? ›

OpenSCAD can import the geometric structure of SVG files.

Can I import an STL file into AutoCAD? ›

It is not possible to import STL-files into AutoCAD-based products. This can be done by other applications, like Inventor.

Can you import an STL file into FreeCAD? ›

However, it turned out to be quite easy to import the design and then convert it into a FreeCAD model. The first thing you do is use the import dialog to bring in the STL file, select the loaded mesh and switch to the Part workbench and use the commands Part->Create Shape from mesh and then Part->Covert to solid.

How do I import STL files? ›

Open the Geometry toolbar and select "Import". Choose "STL" as the file type. Navigate to the location where the STL file is saved and select it.

How to convert STL file to Dicom? ›

How to convert STL to DICOM
  1. Select the file by clicking the STL to DICOM App or simply drag & drop a STL file.
  2. Click the Convert button to upload STL and convert it to a DICOM file.
  3. Click on the Save button when it appears after successful STL to DICOM format conversion.
  4. That is all!

Top Articles
Easy Millionaires Shortbread Recipe | Carnation
40+ Best Christmas Candy Recipes l Kitchen Fun With My 3 Sons
Refinery29 Horoscopes
Which Universal Life Option Has A Gradually
Gasbuddy Costco Hawthorne
Climate change, eroding shorelines and the race to save Indigenous history - The Weather Network
Msc Open House Fall 2023
Fresenius Medical Care to launch 5008 dialysis machine: improved patients` quality of life and efficient use of resources
How Much Food Should I Buy For Christmas? | Gousto Christmas
Best Restaurants In Nyack On The Water
Uscis Fort Myers 3850 Colonial Blvd
Einfaches Spiel programmieren: Schritt-für-Schritt Anleitung für Scratch
Strange World Showtimes Near Cmx Downtown At The Gardens 16
Folsom Gulch Covid
Nail Salon At Legacy Village
Slmd Skincare Appointment
888-490-1703
New York Rangers Hfboards
Nail Shops Open Sunday Near Me
Violent Night Showtimes Near The Grand 16 - Lafayette
Craigslist Apartments For Rent Ozone Park
Mashle: Magic And Muscles Gogoanime
Christopher Goosley Obituary
What Happened To Zion Judah Satterfield
Cavender’s 50th Anniversary: How the Cavender Family Built — and Continues to Grow — a Western Wear Empire Using Common Sense values
10-Day Weather Forecast for New Jersey - The Weather Channel | weather.com
A vintage funfair / fairground
The Nearest Dollar Store To My Location
Cognitive Function Test Potomac Falls
Black Boobs Oiled
Craigslist Lubbick
222 US Dollars to Euros - 222 USD to EUR Exchange Rate
Walgreens On 37Th And Woodlawn
Walgreens Rufe Snow Hightower
Shirley Arica Unlock
631 West Skyline Parkway, Duluth, MN 55806 | Compass
KOBALT K15CS-06AC MANUAL Pdf Download
Danielle Longet
Middletown Pa Craigslist
Lmsyduycdmt
Luchtvaart- en Ruimtevaarttechniek - Technische Universiteit Delft - Studiekeuze123 - Studiekeuze123
Lavender Dreams Nails Walnut Creek Photos
Smartmove Internet Provider
Gasmonkeygarage.com Cars For Sale
Kingdom Tattoo Ithaca Mi
Sparkle Nails Phillipsburg
Netspar on LinkedIn: Netspar is pleased to announce the next Netspar Pension Day, which will…
Azpeople Self Service
Rainfall Map Oklahoma
The Eye Doctors North Topeka
Love In Orbit Manga Buddy
Remembering the life of Jeff Hewson.
Latest Posts
Article information

Author: Tyson Zemlak

Last Updated:

Views: 5758

Rating: 4.2 / 5 (43 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Tyson Zemlak

Birthday: 1992-03-17

Address: Apt. 662 96191 Quigley Dam, Kubview, MA 42013

Phone: +441678032891

Job: Community-Services Orchestrator

Hobby: Coffee roasting, Calligraphy, Metalworking, Fashion, Vehicle restoration, Shopping, Photography

Introduction: My name is Tyson Zemlak, I am a excited, light, sparkling, super, open, fair, magnificent person who loves writing and wants to share my knowledge and understanding with you.