RapCAD imports

The syntax for importing modules into rapcad is quite different from the legacy way of doing it. I decided to break compatibility because of a number of problems with the old syntax, that arise when you want to quickly scan for dependencies. Lets first consider a valid example using the old syntax.

module foo(){
  module bar(){

The first problem with this is that the filename argument is actually an expression. If you were parsing this script to find its dependencies, the parser would have to be able to partially evaluate the script, turning str("file","name",".stl") into the string literal filename.stl. The second problem is that the import statements are nested in several sub constructs, meaning that the parser has to understand these constructs in order to extract the import module statements. Last of all the legacy way of importing seems to be inconsistent with the way ‘use‘ and ‘include‘ statements work.

My solution was to add an import statement which works as follows

import <triceratops.off> as dino;


The import statement appears at the top of the file and it doesn’t take an expression, only a string literal. It cannot be nested, and it fits with the use and include statements. The statement is followed by an ‘as‘ clause and the identifier following the ‘as‘ clause provides a name which can be used to instantiate the imported module. The module can be instantiated any number of times, just as you would any other built-in or user defined module. The module instances can of course be nested in any other construct as required, but the import declaration remains at the top of the file, and so one can easily glean which files the script depends on.

Version 0.3.0 is available this month and is capable of importing OFF files. See the Download Page for details.


3 thoughts on “RapCAD imports”

  1. Does the old syntax still work for OpenSCAD compatibility?

    Also, while we’re changing the way importing is done, it would be nice to be able to import a DXF as a 2D polygon rather than being forced to extrude it at the time of import.

  2. Yes the old syntax will be supported via import_stl() and import_off() modules, however these will raise a subtle warning and will not be supported by the dependency tracker.

    DXF imports will work exactly as you said, so for example if you wanted to emulate the existing dxf_linear_extrude() you would do:

              import <path.dxf>  as shape;
              linear_extrude(h=10) shape();

    Again dxf_linear_extrude() will be there for backwards compatibility with a subtle warning 😉

  3. Technically there is no dxf_linear_extrude() module but it made the intent of my previous comment clearer, what OpenSCAD actually does is overload linear_extrude(). its a technicality that is easily worked around.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s