<p>Given a .SCAD file which contains some modules, how can I execute one of those modules from the command line?</p>
<p><strong>example.scad</strong></p>
<pre><code>module One() { ... }
module Two() { ... }
</code></pre>
<p><strong>render.sh</strong></p>
<pre><code>openscad -q -o one.stl --module One example.scad
</code></pre>
<p>Note that there is no <code>--module</code> option, but that is what I'm attempting to do. The workaround would be to make another .SCAD file e.g. <code>one.scad</code> which includes <code>example.scad</code>, and simply calls <code>One();</code> within and render that file from the shell file. But this is not ideal.</p>

[{'answer_id': 14903, 'author': 'R.. GitHub STOP HELPING ICE', 'author_id': 11157, 'author_profile': 'https://3dprinting.stackexchange.com/users/11157', 'pm_score': 1, 'selected': False, 'text': "<p>OpenSCAD doesn't have such an option on the command line, but the general idiom I believe you want to use is have <code>.scad</code> source files which are modules include invocations of the module(s) at the top-level controllable by variables you can set on the command line or GUI customizer interface. Any such invocations will be ignored if the file is used (via <code>use</code> directive) in another file so they don't hurt its status as a library and make it easier to preview/test. So for example you could have:</p>\n<pre><code>wantOne = false;\nif (wantOne) One();\n</code></pre>\n<p>and then set <code>wantOne</code> to <code>true</code> from the command line.</p>\n"}, {'answer_id': 16206, 'author': 'whitis', 'author_id': 19697, 'author_profile': 'https://3dprinting.stackexchange.com/users/19697', 'pm_score': 2, 'selected': True, 'text': '<p>The <code>openscad -D</code> option can actually include arbitrary code, not just variable definitions, so you can include a call to the module.   You can even use <code>/dev/null</code> on Linux or NUL on Windows as the input file and have 100\xa0% of your code in <code>-D</code> statements.</p>\n'}, {'answer_id': 20210, 'author': 'ellemenno', 'author_id': 36057, 'author_profile': 'https://3dprinting.stackexchange.com/users/36057', 'pm_score': 0, 'selected': False, 'text': '<p>elaborating on the answer from @r-github-stop-helping-ice, I find the following pattern useful:</p>\n<h6>example.scad</h6>\n<pre><code>module a() { .. }\nmodule b() { .. }\nmodule c() { .. }\n\nmodule print(item=0) {\n  if (item==1) a();\n  if (item==2) b();\n  if (item==3) c();\n}\n\nitem = 0;\nprint(item);\n</code></pre>\n<h6>render.sh</h6>\n<pre><code>#!/bin/bash\nfor i in {1..3}; do\n  openscad -D item=${i} -o item_${i}.stl example.scad\ndone\n</code></pre>\n'}]
['https://3dprinting.stackexchange.com/questions/14900', 'https://3dprinting.stackexchange.com', 'https://3dprinting.stackexchange.com/users/25482/']