<p>This seems to be a limitation of the language. One workaround that's only moderately ugly is, in the body of the module:</p>

<pre><code>mouth = is_undef(mouth) ? pin_radius * 0.9 : mouth;
</code></pre>

<p>etc. If you'll only be using the file via a <code>use</code> directive in other files, another approach is file-scope variables. These can be overridden when the module is called, just like module parameters, and they do not provide or take values for/from the calling file's file-scope variable namespace.</p>

CC BY-SA 4.0
2019-07-15T05:27:04.090Z
2019-07-15T05:27:04.090Z
R.. GitHub STOP HELPING ICE
<p>I'm new to OpenSCAD, but I can only get default parameters working for simple values.  </p>

<p>I'm wondering if there is any way to achieve the following, where I have some parameters available to the module caller but by default they are derived from other parameters. </p>

<p>I had expected this to work - I thought the compiler to be able to resolve these variables in-scope during compilation since everything here is deterministic - so perhaps I'm just missing some syntax? If not, is there some better way to achieve this?</p>

<pre><code>module clasp(length=20, 
             pin_radius=5,
             mouth = pin_radius * 0.9,
             inner_radius = pin_radius + 0.25,
             outer_radius = inner_radius * 1.4,
             ) {
  ... do the work ...
}
</code></pre>

<p>Unfortunately this approach leaves mount/inner/outer all <code>undef</code>. </p>

<openscad>
Handing OpenSCAD module parameters derived from other variables
Hamy
# Handing OpenSCAD module parameters derived from other variables

(Asked by: username_0 on 2019-07-15)

I'm new to OpenSCAD, but I can only get default parameters working for simple values.

I'm wondering if there is any way to achieve the following, where I have some parameters available to the module caller but by default they are derived from other parameters.

I had expected this to work - I thought the compiler to be able to resolve these variables in-scope during compilation since everything here is deterministic - so perhaps I'm just missing some syntax? If not, is there some better way to achieve this?

```
module clasp(length=20, 
             pin_radius=5,
             mouth = pin_radius * 0.9,
             inner_radius = pin_radius + 0.25,
             outer_radius = inner_radius * 1.4,
             ) {
  ... do the work ...
}

```

Unfortunately this approach leaves mount/inner/outer all `undef`.

**Tags:** openscad


---

## 1 answers

### Answer by username_1 on 2019-07-15. Score: 2 | Accepted answer

This seems to be a limitation of the language. One workaround that's only moderately ugly is, in the body of the module:

```
mouth = is_undef(mouth) ? pin_radius * 0.9 : mouth;

```

etc. If you'll only be using the file via a `use` directive in other files, another approach is file-scope variables. These can be overridden when the module is called, just like module parameters, and they do not provide or take values for/from the calling file's file-scope variable namespace.


---

