<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Multipart project template others could find useful]]></title><description><![CDATA[<p dir="auto">copy pasta from <a href="https://github.com/jscad/OpenJSCAD.org/discussions/1141" rel="nofollow ugc">https://github.com/jscad/OpenJSCAD.org/discussions/1141</a></p>
<p dir="auto">Sharing this idea and also calling to discuss improvements to it.<br />
Even ideas how jscad could be improved to better facilitate use case like this are welcome.</p>
<p dir="auto">Very often when creating thins for 3d print I have multiple parts, so in time I have created a sort of template I like to use. Even if I have single piece I tend to split design in few parts to more easily handle it.</p>
<p dir="auto">This is the latest iteration that solves few issues for me</p>
<ul>
<li>parameter definition to select a part is generated automatically</li>
<li>no need to declare configurable parameters in each function ( func that creates a part)</li>
<li>can reuse one part in another part</li>
</ul>
<pre><code class="language-js">const jscad = require('@jscad/modeling')
const {sphere, cube} = jscad.primitives 
const {translate} = jscad.transforms

// all of the functions that generate parts will see the parameters without declaring them explicitly
const main = ({//@jscad-params
  size=10, // {type:'slider'}
  part,
}, getParams)=&gt;{

  // UTILITY placeholder for part generator functions
  const parts = {}

  // CTRL+R in vscode works just fine
  parts.Sample_Cube = ()=&gt;cube({size})

  parts.Sample_Sphere = ()=&gt;{
    return sphere({radius:size/2})
  }

  // parts can easily be combined
  parts.Assembly = ()=&gt;([
    // jump to definition in vscode (ALT+click) works
    parts.Sample_Cube(),
    translate([size+5,0,0], parts.Sample_Sphere()),
  ])

  /*********************** UTILITY below is just utility code. do not change **************** */

  // we were called by getParameterDefinitions so we need to provide list of parts
  if(getParams === true){
    const values = Object.keys(parts)
    return {values, initial: values[0]}
  }

  // make sure we always call one of the functions
  if(!parts[part]) part = Object.keys(parts)[0]
  return parts[part]()
}

const getParameterDefinitions = ()=&gt;[{ name: 'part', caption:'Part', type: 'choice', ...main({}, true)}]

module.exports = {main, getParameterDefinitions}
</code></pre>
<p dir="auto"><img src="https://camo.nodebb.org/0ae0b0df44f80b972d97af41278d84f46436bd02?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F2480762%2F187289586-b14edad1-7c4c-4c90-b679-e44a92b08625.png" alt="image" class=" img-responsive img-markdown" /></p>
]]></description><link>https://openjscad.nodebb.com/topic/383/multipart-project-template-others-could-find-useful</link><generator>RSS for Node</generator><lastBuildDate>Tue, 10 Mar 2026 16:07:41 GMT</lastBuildDate><atom:link href="https://openjscad.nodebb.com/topic/383.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 29 Aug 2022 20:20:01 GMT</pubDate><ttl>60</ttl></channel></rss>