Organize your designs with groups and child imports for better structure and reusability.
Groups in STL.Show allow you to organize related objects together, create hierarchical designs, and reference other objects in your JSCAD code. This enables modular design, better organization, and the ability to build complex assemblies from reusable components.
Group related objects together for better structure
Reference objects across multiple designs
Create complex assemblies with nested components
Groups are created in the STL.Show interface and can contain multiple objects, including other groups.
Child imports allow you to reference other objects in your JSCAD code, creating dynamic relationships between different parts of your design.
Child imports let you reference other objects (STL files, JSCAD code, or groups) directly in your JSCAD code. This creates a parent-child relationship where changes to the child object automatically update the parent.
// In your JSCAD code object
// Add this at the top of your file
const childImports = {
'base-plate': 'base-plate-group',
'fasteners': 'fasteners-group'
}function main(params) {
// Access child objects
const basePlate = childImports['base-plate']
const fasteners = childImports['fasteners']
// Use in your design
return union(
basePlate,
translate([0, 0, 10], fasteners)
)
}Note: Child imports are automatically updated when the referenced objects change.
const childImports = {
// Reference by object name
'my-part': 'my-part-object',
// Reference by group name
'assembly': 'assembly-group',
// Reference by file name
'template': 'template-file.stl'
}function main(params) {
// Direct use
const part = childImports['my-part']
// With transformations
const transformed = translate([10, 0, 0], part)
// Multiple parts
const assembly = union(
childImports['part1'],
childImports['part2'],
childImports['part3']
)
return assembly
}Advanced techniques for working with groups and child imports.
Create hierarchical structures by nesting groups within groups.
// Main Assembly
├── Base Group
│ ├── Base Plate
│ └── Mounting Holes
├── Motor Group
│ ├── Motor Housing
│ ├── Shaft
│ └── Bearings
└── Electronics Group
├── Circuit Board
├── Connectors
└── Heat SinkUse parameters to conditionally include different child objects.
function getParameterDefinitions() {
return [
{name: 'version', type: 'choice', values: ['basic', 'pro'],
captions: ['Basic Version', 'Pro Version'], initial: 'basic', caption: 'Version'}
]
}
function main(params) {
const childImports = {
'basic-parts': 'basic-parts-group',
'pro-parts': 'pro-parts-group'
}
if (params.version === 'basic') {
return childImports['basic-parts']
} else {
return union(
childImports['basic-parts'],
childImports['pro-parts']
)
}
}Tip: Use conditional imports to create different versions of your design.
Apply transformations to entire groups and their child imports.
function main(params) {
const childImports = {
'assembly': 'main-assembly-group'
}
// Transform entire assembly
return translate([0, 0, params.height],
rotate([0, 0, params.rotation],
childImports['assembly']
)
)
}A comprehensive example showing how to use groups and child imports to create a modular robot design.
// Main robot assembly
const childImports = {
'base': 'robot-base-group',
'body': 'robot-body-group',
'arms': 'robot-arms-group',
'head': 'robot-head-group',
'wheels': 'robot-wheels-group'
}
function getParameterDefinitions() {
return [
{name: 'includeArms', type: 'checkbox', checked: true, caption: 'Include Arms'},
{name: 'includeHead', type: 'checkbox', checked: true, caption: 'Include Head'},
{name: 'wheelType', type: 'choice', values: ['small', 'large'],
captions: ['Small Wheels', 'Large Wheels'], initial: 'small', caption: 'Wheel Type'},
{name: 'bodyHeight', type: 'number', initial: 20, min: 10, max: 50, caption: 'Body Height'}
]
}
function main(params) {
// Start with base
let robot = childImports['base']
// Add body with height parameter
const body = translate([0, 0, params.bodyHeight], childImports['body'])
robot = union(robot, body)
// Conditionally add arms
if (params.includeArms) {
const leftArm = translate([-15, 0, params.bodyHeight + 10], childImports['arms'])
const rightArm = translate([15, 0, params.bodyHeight + 10], childImports['arms'])
robot = union(robot, leftArm, rightArm)
}
// Conditionally add head
if (params.includeHead) {
const head = translate([0, 0, params.bodyHeight + 25], childImports['head'])
robot = union(robot, head)
}
// Add wheels based on type
const wheelGroup = params.wheelType === 'small' ?
childImports['wheels'] :
scale([1.5, 1.5, 1.5], childImports['wheels'])
const leftWheels = translate([-10, 0, 0], wheelGroup)
const rightWheels = translate([10, 0, 0], wheelGroup)
robot = union(robot, leftWheels, rightWheels)
return robot
}Create component groups
Define child imports
Add conditional logic
Assemble with transforms
Guidelines for effective use of groups and child imports.
Now that you understand groups and child imports, explore these advanced topics: