Directories in OpenSCAD

Here’s the translation of the Go code example to OpenSCAD, formatted in Markdown suitable for Hugo:

Our first program will create a simple 3D model using OpenSCAD. Here’s the full source code:

// Create a cylinder
cylinder(h = 10, r = 5);

// Create a cube and translate it
translate([10, 0, 0]) {
    cube([5, 5, 5]);
}

// Create a sphere
translate([-10, 0, 0]) {
    sphere(r = 3);
}

// Output a message to the console
echo("Hello, OpenSCAD!");

To run this OpenSCAD script:

  1. Save the code in a file with a .scad extension, for example, hello_openscad.scad.
  2. Open the file in the OpenSCAD application.
  3. Click on “Compile and Render” (F6) to see the 3D model.
  4. The console output can be seen in the console window, usually at the bottom of the application.

OpenSCAD doesn’t have a traditional “hello world” text output, as it’s primarily used for creating 3D models. However, we can use the echo() function to output messages to the console.

When you run this script, you’ll see a 3D scene with three objects:

  • A cylinder in the center
  • A cube to the right of the cylinder
  • A sphere to the left of the cylinder

In the console, you’ll see the message:

ECHO: "Hello, OpenSCAD!"

This demonstrates basic shape creation, positioning, and console output in OpenSCAD.

OpenSCAD doesn’t have a build process like compiled languages. Instead, you typically work with .scad files directly in the OpenSCAD application, and export to various 3D file formats (like STL) when you need to use the model in other applications or for 3D printing.

Now that we can create basic OpenSCAD models and use console output, let’s explore more features of the language.