Jump to content

OpenSCAD User Manual/WIP/Migration Guide

From Wikibooks, open books for an open world

OpenSCAD 2019 contains changes that break some old design and/or create errors and warnings for code that previously did not.

Variables

[edit | edit source]

Duplicate assignment warning

[edit | edit source]

In the following cases OpenSCAD 2019 creates a warning in case of a duplicate assignment:

  • variable overwritten in the same file and scope
  • assignment from the mainFile overwritten by an include

In the following cases, the variable is silently overwritten by the last assignment:

  • assignment via command line
  • variable of an include over written by the main file

uninitialized special variables

[edit | edit source]

This code now causes a warning, as $test is not initialized:

test = $test==undef ? 1 : $test ;

The workaround is the new is_undef() function:

test = is_undef($test) ? 1 : $test ;

Module and function arguments

[edit | edit source]

argument types

[edit | edit source]

Built in functions and modules now warn, when the argument type does not match.

As type checking previously was done by using the built in functions returning undef, it is now recommended/required to use is_list(), is_num(), is_bool() and is_string() for type checking.

duplicate arguments

[edit | edit source]

OpenSCAD 2019 warns when a named argument is supplied more than once.

cube(size=2,size=1);

not specified arguments

[edit | edit source]

OpenSCAD now warns, when a module or function parameter is not declared.

user modules

[edit | edit source]

Meaning, this now causes a warning:

a=1;

module test(){
    cube(a);
}

test();

translate([2,0,0])
test(a=2);

If doing that is your intention - like in the Write.scad library - you can update the code as follows:

a=1;

module test(a){
    cube(a);
}

test();

translate([2,0,0])
test(a=2);

For Write.scad specifically: Definitions like

module writecircle(text,where,radius){

need to change to

module writecircle(text, where, radius, rotate, font, h, t, spac, east, west, middle, ccw){
</syntaxhighlight lang="unknown">
==== builtin modules ====
Same goes for builtin modules, so this now creates a warning:
<syntaxhighlight lang="text">
sphere(center=true);

and

circle(center=true);

Neither circle nor sphere support the center argument - center and circle are always centered.

An other example is

circle(radius=5);

as circle excepts r, not radius.

arguments overwritten by literal

[edit | edit source]
module test(a){
    a=2;
    sphere(a);
}

test();

translate([4,0,0])
test(a=1);

Note that this very similar example does not trigger a warning, due to quirks in the implementation:

module test(a){
    a=1+1;
    sphere(a);
}

test();

translate([4,0,0])
test(a=2);

arguments range check for builtin modules

[edit | edit source]

things like

cube(-1);
cube([1,1,-1]);
cube(0);
cube([1,1,0]);

argument conflict check for builtin modules

[edit | edit source]
cylinder(h = 1, r1 = 0, r2 = 1, d = 2, center = true);

argument count for builtin functions

[edit | edit source]

If the argument count for builtin functions does not match, OpenSCAD 2019 displays a warning:

echo(abs(123,456));

assert()

[edit | edit source]

The builtin Assert can not be overwritten by a user function or module. If you have a function or module named as assert, you must rename it.