Repository navigation
Model definition
Advanced topic. This page is for persons who write OpenSCAD models.
The model definition is a YAML file next to the model: box.yml for box.scad. The .scad file holds only OpenSCAD code. The definition holds the rest:
- The title, the description and other text about the model.
- The names and the colors of the parts.
- The parameter sets.
All items are optional. A model without a definition works in CgeoCAD too.
# yaml-language-server: $schema=https://cad.cgeosoft.com/schema/model-1.json
cgeocad: 1
title: Part selector
description: A box with a lid and four feet.
author: Your name
license: MIT
url: https://example.com/part-selector
parts:
- id: box
name: Box
color: "#4e8fd6"
- id: lid
name: Lid
color: "#59a14f"
- id: feet
name: Foot
color: "#e15759"
sets:
Small box:
description: The default box.
Card box:
description: A box for playing cards.
values:
width: 65
depth: 80
lid_t: 4The examples in File > Examples all have a definition. CgeoCAD writes them to the examples folder of the settings folder.
| Key | Value |
|---|---|
cgeocad |
The version of the format: 1. CgeoCAD does not read a file with a newer version. Files of version 0.8 have the old key cocad: 1: CgeoCAD reads it, and the next save writes cgeocad: 1 in its place. With both keys, cgeocad wins and a warning shows. |
title |
The name of the model. The Parameters panel and the start page show it. |
description |
What the model is. |
author, version, license, url
|
More text about the model. |
parts |
The part names. See Parts. |
part_parameter |
The parameter that selects a part. Default: part. |
multicolor |
true: the parts are the colors of one object. See Multicolor prints. Default: false. |
sets |
The parameter sets. See Sets. |
units |
The values of the units of the model. See Units. |
plugins |
The plugins of the model, each with the exact version of its library. Optional. |
settings |
Plugin settings of this model, by plugin id. Optional. |
x-... |
A key for other tools. CgeoCAD does not read it. |
The model selects one part with a string parameter. The value all shows all parts:
part = "all"; // [all, box, lid, feet]
if (part == "all" || part == "box") box();
if (part == "all" || part == "lid") lid();
if (part == "all" || part == "feet") feet();The parts list of the definition gives each other value a name:
parts:
- id: box # the value of the part parameter
name: Box # the name that CgeoCAD shows
color: "#4e8fd6" # quotes: without them, # starts a comment
- id: lid
name: Lid
- feet # only the id: the name is "feet"- The order of the list is the order in the dropdown list of the parameter. For a multicolor model, it also sets the filament number.
-
colorsets the color of a part:#RRGGBBor a color name (white, black, red, green, blue, yellow, orange, purple, pink, brown, cyan, magenta, gold, silver, gray). The 3D view, the thumbnail and the photo with Part colors on show the part in this color. Colors… in the Parts card can change it. In a multicolor model, it is also the color of the filament. - The parameter must be a string parameter in the
.scadfile, not in theHiddengroup. A dropdown list in the.scadfile is optional. With the list, the part selection also works in the OpenSCAD Customizer. The names of the definition replace the labels of the list. - For the rules of the parts, see Write models for CgeoCAD.
sets:
Big:
description: For the workshop.
values:
width: 80 # number
shape: round # text
label: "5" # text that looks like a number: use quotes
lid: true # true or false
offset: [0, 5] # vectorA parameter that is not in the set keeps the default of the model. A set without values gives the defaults. See Parameter sets.
A model with the CgeoCAD library can have units: parts that you click and change in the Unit card (see Units). CgeoCAD writes the values into the units block:
units:
shelf: # the id of the unit in cgeocad_unit()
brackets: 3 # the key of a field and its value
width: 900
plugins: { slotted-angle: 0.1.0 }
settings:
slotted-angle: { kerf: 1.5 }- A value is a number,
trueorfalse, or a text. - CgeoCAD gives the values to OpenSCAD as
$cgeocad_values, and the settings as$cgeocad_settings. The.scadfile does not change. - A change in the Unit card writes only the
unitsblock again. The other blocks and their comments stay. - A value for a unit that the model does not have stays in the file and gives a note. A value of the wrong type or out of the limits is not used and gives a note.
- Version 0.8 shows these keys as unknown keys and does not use them.
- A file that CgeoCAD cannot read gives a message, and the model opens without the definition.
- An unknown key, a part without an
idor a wrong color gives a warning. CgeoCAD does not use that entry. The warnings show in a message and at the top of the OpenSCAD output. - A
partslist for a parameter that the model does not have gives a warning. CgeoCAD then uses the dropdown list of the.scadfile.
The JSON Schema of the format is at https://cad.cgeosoft.com/schema/model-1.json. The old address in files of version 0.8, https://cocad.cgeosoft.com/schema/model-1.json, gives the same file. The schema allows the key cgeocad and the old key cocad. The first line of the example tells the YAML extension of VS Code and other editors to use it. The editor then completes the keys and marks the errors.
Version 0.7 kept the sets in box.json, in the format of the OpenSCAD Customizer. The part names were the labels of the part list, and a multicolor model had a cocad_part list and echo(cocad_color = ...). CgeoCAD was CoCAD before 0.9: these old names stay readable.
- A model without a
.ymlfile and with a.jsonfile: CgeoCAD reads the sets and the text of the.jsonfile. The first save of a set writes the.ymlfile. The.jsonfile stays. - Without
partsin the definition, the labels of apartlist are the part names, and acocad_partorcgeocad_partlist is a multicolor list.echo(cocad_color = ...)orecho(cgeocad_color = ...)sets the color of a part without acolorin the definition. - For OpenSCAD,
cgeocad sets box.scad --jsonwrites the sets in the Customizer format:openscad -p <(cgeocad sets box.scad --json) -P Big -o big.stl box.scad.
Home · Glossary · Problems and answers · Download · Website
The source of these pages is the docs/wiki/ folder of the repository. Changes that you make on the wiki website are lost at the next update.
Start
Look at the model
Furniture
Projects
More
Advanced