package OSCADml

  1. Overview
  2. Docs

Exporting .scad scripts through the OpenSCAD command line interface.

2D/3D formats

val script : string -> string -> (unit, string) Stdlib.result

script out_path in_path

Export the .scad script at in_path to a file at the given out_path, in a format dictated by the extension of out_path. See documentation for the -o argument in the OpenSCAD CLI docs for available output formats. If export fails, an error containing captured Stderr output from OpenSCAD is returned (usually CGAL errors).

Images (PNG)

type colorscheme =
  1. | Cornfield
  2. | Metallic
  3. | Sunset
  4. | Starnight
  5. | BeforeDawn
  6. | Nature
  7. | DeepOcean
  8. | Solarized
  9. | Tomorrow
  10. | TomorrowNight
  11. | Monotone

OpenSCAD colour palettes

type projection =
  1. | Perspective
  2. | Orthogonal

View projection (as in OpenSCAD GUI)

type view =
  1. | Axes
  2. | Crosshairs
  3. | Edges
  4. | Scales
  5. | Wireframe

View options (as in OpenSCAD GUI)

type camera =
  1. | Auto
    (*

    Automatically positon to view all of the object, and point at it's centre.

    *)
  2. | Gimbal of {
    1. translation : OCADml.v3;
      (*

      origin shift vector

      *)
    2. rotation : OCADml.v3;
      (*

      euler rotation vector (about translated origin)

      *)
    3. distance : [ `Auto | `D of float ];
      (*

      vertical distance of camera above shifted origin before rotation (auto moves far enough away to bring object fully into frame)

      *)
    }
  3. | Eye of {
    1. lens : OCADml.v3;
      (*

      lens position vector

      *)
    2. center : OCADml.v3;
      (*

      center position vector (which lens points towards)

      *)
    3. view_all : bool;
      (*

      override vector distance to ensure all object is visible

      *)
    }

Camera position and orientation configuration

val auto : camera

Position camera such that object is centred and fully in view.

val gimbal : ?translation:OCADml.v3 -> ?rotation:OCADml.v3 -> [ `Auto | `D of float ] -> camera

gimbal ?translation ?rotation d

Position and orient the camera as in the OpenSCAD GUI with translation, and euler rotation vectors a (defaulting to V3.zero). The focal point is moved from the origin by translation, then the camera is positioned the distance d (manually, or far enough back to get the whole object into frame) straight upward in z before applying the euler rotation.

val eye : ?view_all:bool -> ?center:OCADml.v3 -> OCADml.v3 -> camera

eye ?view_all ?center lens

Position the camera at lens, and point it at center. If view_all is true, then the camera will be moved along the difference vector to bring the whole object into the frame.

val snapshot : ?render:bool -> ?colorscheme:colorscheme -> ?view:view list -> ?projection:projection -> ?size:(int * int) -> ?camera:camera -> string -> string -> (unit, string) Stdlib.result

snapshot ?render ?colorscheme ?view ?projection ?size ?camera out_path in_path

Save an image (PNG only at this time) of size pixels (default = (500, 500)) to out_path of the object defined by the .scad script located at in_path using the OpenSCAD CLI. By default, the camera is positioned automatically to point at the centre of the object, and far enough away such for it to all be in frame. See camera and its gimbal and eye constructors for details on manual control. If export fails, an error containing captured Stderr output from OpenSCAD is returned (usually CGAL errors).

  • if render is true, the object will be rendered before the snapshot is taken, otherwise preview mode is used (default = false).
  • view toggles on various viewport elements such as axes and scale ticks
  • projection sets the view style as in the GUI (default = Perspective)
  • colorscheme selects the OpenSCAD colour palette (default = Cornfield)

File extension helpers

module ExtMap : Stdlib.Map.S with type key = string
type ext2 = [
  1. | `Csg
  2. | `Dxf
  3. | `Svg
]
type ext3 = [
  1. | `Amf
  2. | `Csg
  3. | `Off
  4. | `Stl
  5. | `Wrl
  6. | `_3mf
]
val d2_exts : [> ext2 ] ExtMap.t

Set of 2D output format file extensions: ".dxf", ".svg", ".csg"

val d3_exts : [> ext3 ] ExtMap.t

Set of 3D output format file extensions: ".stl", ".off", ".amf", ".3mf", ".csg", ".wrl"

legal_ext allowed path

Check whether the extention of the file at path is in the allowed, returning it as the error string if not.