1Documenting OpenSCAD Code
2-------------------------------------------------
3
4Documentation comment blocks are all based around a single simple syntax:
5
6 // Block Name(Metadata): TitleText
7 // Body line 1
8 // Body line 2
9 // Body line 3
10
11- The Block Name is one or two words, both starting with a capital letter.
12- The Metadata is in parentheses. It is optional, and can contain fairly arbitrary text, as long as it doesn't include newlines or parentheses. If the Metadata part is not given, the parentheses are optional.
13- A colon `:` will always follow after the Block Name and optional Metadata.
14- The TitleText will be preceded by a space ` `, and can contain arbitrary text, as long as it contains no newlines. The TitleText part is also optional for some header blocks.
15- The body will contain zero or more lines of text indented by three spaces after the comment markers. Each line can contain arbitrary text.
16
17So, for example, a Figure block to show a 640x480 animated GIF of a spinning shape may look like:
18
19 // Figure(Spin,Size=640x480,VPD=444): A Cube and Cylinder.
20 // cube(80, center=true);
21 // cylinder(h=100,d=60,center=true);
22
23Various block types don't need all of those parts, so they may look simpler:
24
25 // Topics: Mask, Cylindrical, Attachable
26
27Or:
28
29 // Description:
30 // This is a description.
31 // It can be multiple lines in length.
32
33Or:
34
35 // Usage: Typical Usage
36 // x = foo(a, b, c);
37 // x = foo([a, b, c, ...]);
38
39Comments blocks that don't start with a known block header are ignored and not added to output documentation. This lets you have normal comments in your code that are not used for documentation. If you must start a comment block with one of the known headers, then adding a single extra `/` or space after the comment marker, will make it be treated as a regular comment:
40
41 /// File: Foobar.scad
42
43
44Block Headers
45=======================
46
47File/LibFile Blocks
48-------------------
49
50All files must have either a `// File:` block or a `// LibFile:` block at the start. This is the place to put in the canonical filename, and a description of what the file is for. These blocks can be used interchangably, but you can only have one per file. `// File:` or `// LibFile:` blocks can be followed by a multiple line body that are added as markdown text after the header:
51
52 // LibFile: foo.scad
53 // You can have several lines of markdown formatted text here.
54 // You just need to make sure that each line is indented, with
55 // at least three spaces after the comment marker. You can
56 // denote a paragraph break with a comment line with three
57 // trailing spaces, or just a period.
58 // .
59 // You can have links in this text to functions, modules, or
60 // constants in other files by putting the name in double-
61 // braces like {{cyl()}} or {{lerp()}} or {{DOWN}}. If you want to
62 // link to another file, or section in another file you can use
63 // a manual markdown link like [Section: Cuboids](shapes.scad#section-cuboids).
64 // The end of the block is denoted by a line without a comment.
65
66Which outputs Markdown code that renders like:
67
68> ## LibFile: foo.scad
69> You can have several lines of markdown formatted text here.
70> You just need to make sure that each line is indented, with
71> at least three spaces after the comment marker. You can
72> denote a paragraph break with a comment line with three
73> trailing spaces, or just a period.
74>
75> You can have links in this text to functions, modules, or
76> constants in other files by putting the name in double-
77> braces like [cyl()](shapes.scad#functionmodule-cyl) or [lerp()](math.scad#function-lerp) or [DOWN](constants.scad-down). If you want to
78> link to another file, or section in another file you can use
79> a manual markdown link like [Section: Cuboids](shapes.scad#section-cuboids).
80> The end of the block is denoted by a line without a comment.
81
82You can use `// File:` instead of `// LibFile:`, if it seems more apropriate for your particular context:
83
84 // File: Foobar.scad
85 // This file contains a collection of metasyntactical nonsense.
86
87Which outputs Markdown code that renders like:
88
89> # File: Foobar.scad
90> This file contains a collection of metasyntactical nonsense.
91
92
93FileGroup Block
94---------------
95
96You can specify what group of files this .scad file is a part of with the `// FileGroup:` block:
97
98 // FileGroup: Advanced Modeling
99
100This affects the ordering of files in Table of Contents and CheatSheet files. This doesn't generate any output text otherwise.
101
102
103FileSummary Block
104-----------------
105
106You can give a short summary of the contents of this .scad file with the `// FileSummary:` block:
107
108 // FileSummary: Various modules to generate Foobar objects.
109
110This summary is used when summarizing this .scad file in the Table of Contents file. This will result in a line in the Table of Contents that renders like:
111
112> - [Foobar.scad](Foobar.scad): Various modules to generate Foobar objects.
113
114
115FileFootnotes Block
116-------------------
117
118You can specify footnotes that are appended to this .scad file's name wherever the list of files is shown, such as in the Table of Contents. You can do this with the `// FileFootnotes:` block. The syntax looks like:
119
120 // FileFootnotes: 1=First Footnote; 2=Second Footnote
121
122Multiple footnotes are separated by semicolons (`;`). Within each footnote, you specify the footnote symbol and the footnote text separated by an equals sign (`=`). The footnote symbol may be more than one character, like this:
123
124 // FileFootnotes: STD=Included in std.scad
125
126This will result in footnote markers that render like:
127
128> - Foobar.scad<sup id="fn_std">[STD](#footnote-std "Included in std.scad")</sup>
129
130
131Includes Block
132--------------
133
134To declare what code the user needs to add to their code to include or use this library file, you can use the `// Includes:` block. You should put this right after the `// File:` or `// LibFile:` block. This code block will also be prepended to all Example and Figure code blocks before they are evaluated:
135
136 // Includes:
137 // include <BOSL2/std.scad>
138 // include <BOSL2/beziers.scad>
139
140Which outputs Markdown code that renders like:
141
142> **Includes:**
143>
144> To use, add the following lines to the beginning of your file:
145>
146> ```openscad
147> include <BOSL2/std.scad>
148> include <BOSL2/beziers.scad>
149> ```
150
151
152CommonCode Block
153----------------
154
155If you have a block of code you plan to use throughout the file's Figure or Example blocks, and you don't actually want it displayed, you can use a `// CommonCode:` block like thus:
156
157 // CommonCode:
158 // module text3d(text, h=0.01, size=3) {
159 // linear_extrude(height=h, convexity=10) {
160 // text(text=text, size=size, valign="center", halign="center");
161 // }
162 // }
163
164This doesn't have immediately visible markdown output, but you *can* use that code in later examples:
165
166 // Example:
167 // text3d("Foobar");
168
169
170Section Block
171-------------
172
173Section blocks take a title, and an optional body that will be shown as the description of the Section. If a body line if just a `.` (dot, period), then that line is treated as a blank line in the output:
174
175 // Section: Foobar
176 // You can have several lines of markdown formatted text here.
177 // You just need to make sure that each line is indented, with
178 // at least three spaces after the comment marker. You can
179 // denote a paragraph break with a comment line with three
180 // trailing spaces, or just a period.
181 // .
182 // You can have links in this text to functions, modules, or
183 // constants in other files by putting the name in double-
184 // braces like {{cyl()}} or {{lerp()}} or {{DOWN}}. If you want to
185 // link to another file, or section in another file you can use
186 // a manual markdown link like [Section: Cuboids](shapes.scad#section-cuboids).
187 // .
188 // The end of the block is denoted by a line without a comment.
189 // or a line that is unindented after the comment.
190
191Which outputs Markdown code that renders like:
192
193> ## Section: Foobar
194> You can have several lines of markdown formatted text here.
195> You just need to make sure that each line is indented, with
196> at least three spaces after the comment marker. You can
197> denote a paragraph break with a comment line with three
198> trailing spaces, or just a period.
199>
200> You can have links in this text to functions, modules, or
201> constants in other files by putting the name in double-
202> braces like [cyl()](shapes.scad#functionmodule-cyl) or [lerp()](math.scad#function-lerp) or [DOWN](constants.scad-down). If you want to
203> link to another file, or section in another file you can use
204> a manual markdown link like [Section: Cuboids](shapes.scad#section-cuboids).
205>
206> The end of the block is denoted by a line without a comment.
207> or a line that is unindented after the comment.
208
209Sections can also include Figures; images generated from code that is not shown in a code block.
210
211
212Subsection Block
213----------------
214
215Subsection blocks take a title, and an optional body that will be shown as the description of the Subsection. A Subsection must be within a declared Section. If a body line is just a `.` (dot, period), then that line is treated as a blank line in the output:
216
217 // Subsection: Foobar
218 // You can have several lines of markdown formatted text here.
219 // You just need to make sure that each line is indented, with
220 // at least three spaces after the comment marker. You can
221 // denote a paragraph break with a comment line with three
222 // trailing spaces, or just a period.
223 // .
224 // You can have links in this text to functions, modules, or
225 // constants in other files by putting the name in double-
226 // braces like {{cyl()}} or {{lerp()}} or {{DOWN}}. If you want to
227 // link to another file, or section in another file you can use
228 // a manual markdown link like [Subsection: Foo](shapes.scad#subsection-foo).
229 // .
230 // The end of the block is denoted by a line without a comment.
231 // or a line that is unindented after the comment.
232
233Which outputs Markdown code that renders like:
234
235> ## Subsection: Foobar
236> You can have several lines of markdown formatted text here.
237> You just need to make sure that each line is indented, with
238> at least three spaces after the comment marker. You can
239> denote a paragraph break with a comment line with three
240> trailing spaces, or just a period.
241>
242> You can have links in this text to functions, modules, or
243> constants in other files by putting the name in double-
244> braces like [cyl()](shapes.scad#functionmodule-cyl) or [lerp()](math.scad#function-lerp) or [DOWN](constants.scad-down). If you want to
245> link to another file, or section in another file you can use
246> a manual markdown link like [Subsection: Foo](shapes.scad#subsection-foo).
247>
248> The end of the block is denoted by a line without a comment.
249> or a line that is unindented after the comment.
250
251Subsections can also include Figures; images generated from code that is not shown in a code block.
252
253
254Item Blocks
255-----------
256
257Item blocks headers come in four varieties: `Constant`, `Function`, `Module`, and `Function&Module`.
258
259The `Constant` header is used to document a code constant. It should have a Description sub-block, and Example sub-blocks are recommended:
260
261 // Constant: PHI
262 // Description: The golden ratio phi.
263 PHI = (1+sqrt(5))/2;
264
265Which outputs Markdown code that renders like:
266
267> ### Constant: PHI
268> **Description:**
269> The golden ration phi.
270
271
272The `Module` header is used to document a module. It should have a Description sub-block. It is recommended to also have Usage, Arguments, and Example/Examples sub-blocks. The Usage sub-block body lines are also used when constructing the Cheat Sheet index file:
273
274 // Module: cross()
275 // Usage:
276 // cross(size);
277 // Description:
278 // Creates a 2D cross/plus shape.
279 // Arguments:
280 // size = The scalar size of the cross.
281 // Example(2D):
282 // cross(size=100);
283 module cross(size=1) {
284 square([size, size/3], center=true);
285 square([size/3, size], center=true);
286 }
287
288Which outputs Markdown code that renders like:
289
290> ### Module: cross()
291> **Usage:**
292> - cross(size);
293>
294> **Description:**
295> Creates a 2D cross/plus shape.
296>
297> **Arguments:**
298> Positional Arg | What it does
299> -------------------- | -------------------
300> size | The scalar size of the cross.
301>
302> **Example:**
303> ```openscad
304> cross(size=100);
305> ```
306> GENERATED IMAGE GOES HERE
307
308
309The `Function` header is used to document a function. It should have a Description sub-block. It is recommended to also have Usage, Arguments, and Example/Examples sub-blocks. By default, Examples will not generate images for function blocks. Usage sub-block body lines are also used when constructing the Cheat Sheet index file:
310
311 // Function: vector_angle()
312 // Usage:
313 // ang = vector_angle(v1, v2);
314 // Description:
315 // Calculates the angle between two vectors in degrees.
316 // Arguments:
317 // v1 = The first vector.
318 // v2 = The second vector.
319 // Example:
320 // v1 = [1,1,0];
321 // v2 = [1,0,0];
322 // angle = vector_angle(v1, v2);
323 // // Returns: 45
324 function vector_angle(v1,v2) =
325 acos(max(-1,min(1,(vecs[0]*vecs[1])/(norm0*norm1))));
326
327Which outputs Markdown code that renders like:
328
329> ### Function: vector_angle()
330> **Usage:**
331> - ang = vector_angle(v1, v2);
332>
333> **Description:**
334> Calculates the angle between two vectors in degrees.
335>
336> **Arguments:**
337> Positional Arg | What it does
338> -------------------- | -------------------
339> `v1` | The first vector.
340> `v2` | The second vector.
341>
342> **Example:**
343> ```openscad
344> v1 = [1,1,0];
345> v2 = [1,0,0];
346> angle = vector_angle(v1, v2);
347> // Returns: 45
348> ```
349
350The `Function&Module` header is used to document a function which has a related module of the same name. It should have a Description sub-block. It is recommended to also have Usage, Arguments, and Example/Examples sub-blocks. You should have Usage blocks for both calling as a function, and calling as a module. Usage sub-block body lines are also used in constructing the Cheat Sheet index file:
351
352 // Function&Module: oval()
353 // Topics: 2D Shapes, Geometry
354 // Usage: As a Module
355 // oval(rx,ry);
356 // Usage: As a Function
357 // path = oval(rx,ry);
358 // Description:
359 // When called as a function, returns the perimeter path of the oval.
360 // When called as a module, creates a 2D oval shape.
361 // Arguments:
362 // rx = X axis radius.
363 // ry = Y axis radius.
364 // Example(2D): Called as a Function
365 // path = oval(100,60);
366 // polygon(path);
367 // Example(2D): Called as a Module
368 // oval(80,60);
369 module oval(rx,ry) {
370 polygon(oval(rx,ry));
371 }
372 function oval(rx,ry) =
373 [for (a=[360:-360/$fn:0.0001]) [rx*cos(a),ry*sin(a)];
374
375Which outputs Markdown code that renders like:
376
377> ### Function&Module: oval()
378> **Topics:** 2D Shapes, Geometry
379>
380> **Usage:** As a Module
381>
382> - oval(rx,ry);
383>
384> **Usage:** As a Function
385>
386> - path = oval(rx,ry);
387>
388> **Description:**
389> When called as a function, returns the perimeter path of the oval.
390> When called as a module, creates a 2D oval shape.
391>
392> **Arguments:**
393> Positional Arg | What it does
394> -------------------- | -------------------
395> rx | X axis radius.
396> ry | Y axis radius.
397>
398> **Example:** Called as a Function
399>
400> ```openscad
401> path = oval(100,60);
402> polygon(path);
403> ```
404> GENERATED IMAGE SHOWN HERE
405>
406> **Example:** Called as a Module
407>
408> ```openscad
409> oval(80,60);
410> ```
411> GENERATED IMAGE SHOWN HERE
412
413These Type blocks can have a number of sub-blocks. Most sub-blocks are optional, The available standard sub-blocks are:
414
415- `// Aliases: alternatename(), anothername()`
416- `// Status: DEPRECATED`
417- `// Topics: Comma, Delimited, Topic, List`
418- `// Usage:`
419- `// Description:`
420- `// Figure:` or `// Figures`
421- `// Continues:`
422- `// Arguments:`
423- `// See Also: otherfunc(), othermod(), OTHERCONST`
424- `// Example:` or `// Examples:`
425
426
427Aliases Block
428-------------
429
430The Aliases block is used to give alternate names for a function, module, or
431constant. This is reflected in the indexes generated. It looks like:
432
433 // Aliases: secondname(), thirdname()
434
435Which outputs Markdown code that renders like:
436
437> **Aliases:** secondname(), thirdname()
438
439
440Status Block
441------------
442
443The Status block is used to mark a function, module, or constant as deprecated:
444
445 // Status: DEPRECATED, use foo() instead
446
447Which outputs Markdown code that renders like:
448
449> **Status:** DEPRECATED, use foo() instead
450
451
452Topics Block
453------------
454
455The Topics block can associate various topics with the current function or module. This can be used to make an index of Topics:
456
457 // Topics: 2D Shapes, Geometry, Masks
458
459Which outputs Markdown code that renders like:
460
461> **Topics:** 2D Shapes, Geometry, Masks
462
463
464Usage Block
465-----------
466
467The Usage block describes the various ways that the current function or module can be called, with the names of the arguments. By convention, the first few arguments that can be called positionally just have their name shown. The remaining arguments that should be passed by name, will have the name followed by an `=` (equal sign). Arguments that are optional in the given Usage context are shown in `[` and `]` angle brackets. Usage sub-block body lines are also used when constructing the Cheat Sheet index file:
468
469 // Usage: As a Module
470 // oval(rx, ry, <spin=>);
471 // Usage: As a Function
472 // path = oval(rx, ry, <spin=>);
473
474Which outputs Markdown code that renders like:
475
476> **Usage:** As a Module
477> - oval(rx, ry, <spin=>);
478>
479> **Usage:** As a Function
480>
481> - path = oval(rx, ry, <spin=>);
482
483
484Description Block
485-----------------
486The Description block just describes the currect function, module, or constant:
487
488 // Descripton: This is the description for this function or module.
489 // It can be multiple lines long. Markdown syntax code will be used
490 // verbatim in the output markdown file, with the exception of `_`,
491 // which will traslate to `\_`, so that underscores in function/module
492 // names don't get butchered. A line with just a period (`.`) will be
493 // treated as a blank line.
494 // .
495 // You can have links in this text to functions, modules, or
496 // constants in other files by putting the name in double-
497 // braces like {{cyl()}} or {{lerp()}} or {{DOWN}}. If you want to
498 // link to another file, or section in another file you can use
499 // a manual markdown link like [Section: Cuboids](shapes.scad#section-cuboids).
500
501Which outputs Markdown code that renders like:
502
503> **Description:**
504> It can be multiple lines long. Markdown syntax code will be used
505> verbatim in the output markdown file, with the exception of `_`,
506> which will traslate to `\_`, so that underscores in function/module
507> names don't get butchered. A line with just a period (`.`) will be
508> treated as a blank line.
509>
510> You can have links in this text to functions, modules, or
511> constants in other files by putting the name in double-
512> braces like [cyl()](shapes.scad#functionmodule-cyl) or [lerp()](math.scad#function-lerp) or [DOWN](constants.scad-down). If you want to
513> link to another file, or section in another file you can use
514> a manual markdown link like [Section: Cuboids](shapes.scad#section-cuboids).
515
516
517Continues Block
518---------------
519The Continues block can be used to continue the body text of a previous block that has been interrupted by a Figure:
520
521 // Descripton: This is the description for this function or module. It can be
522 // many lines long. If you need to show an image in the middle of this text,
523 // you can use a Figure, like this:
524 // Figure(2D): A circle with a square cutout.
525 // difference() {
526 // circle(d=100);
527 // square(100/sqrt(2), center=true);
528 // }
529 // Continues: You can continue the description text here. It can also be
530 // multiple lines long. This continuation will not print a header.
531
532Which outputs Markdown code that renders like:
533
534> **Descripton:**
535> This is the description for this function or module. It can be
536> many lines long. If you need to show an image in the middle of this text,
537> you can use a Figure, like this:
538>
539> **Figure 1:** A circle with a square cutout.
540> GENERATED IMAGE SHOWN HERE
541>
542> You can continue the description text here. It can also be
543> multiple lines long. This continuation will not print a header.
544>
545
546
547Arguments Block
548---------------
549The Arguments block creates a table that describes the positional arguments for a function or module, and optionally a second table that describes named arguments:
550
551 // Arguments:
552 // v1 = This supplies the first vector.
553 // v2 = This supplies the second vector.
554 // ---
555 // fast = Use fast, but less comprehensive calculation method.
556 // bar = Takes an optional `bar` struct. See {{bar()}}.
557 // dflt = Default value.
558
559Which outputs Markdown code that renders like:
560
561> **Arguments:**
562> Positional Arg | What it Does
563> -------------- | ---------------------------------
564> `v1` | This supplies the first vector.
565> `v2` | The supplies the second vector.
566>
567> Named Arg | What it Does
568> -------------- | ---------------------------------
569> `fast` | If true, use fast, but less accurate calculation method.
570> `bar` | Takes an optional `bar` struct. See [bar()](foobar.scad#function-bar).
571> `dflt` | Default value.
572
573
574See Also Block
575--------------
576
577The See Also block is used to give links to related functions, modules, or
578constants. It looks like:
579
580 // See Also: relatedfunc(), similarmodule()
581
582Which outputs Markdown code that renders like:
583
584> **See Also:** [relatedfunc()](otherfile.scad#relatedfunc), [similarmodule()](otherfile.scad#similarmodule)
585
586
587Figure Block
588--------------
589
590A Figure block generates and shows an image from a script in the multi-line body, by running it in OpenSCAD. A Figures block (plural) does the same, but treats each line of the body as a separate Figure block:
591
592 // Figure: Figure description
593 // cylinder(h=100, d1=75, d2=50);
594 // up(100) cylinder(h=100, d1=50, d2=75);
595 // Figure(Spin,VPD=444): Animated figure that spins to show all faces.
596 // cube([10,100,50], center=true);
597 // cube([100,10,30], center=true);
598 // Figures:
599 // cube(100);
600 // cylinder(h=100,d=50);
601 // sphere(d=100);
602
603Which outputs Markdown code that renders like:
604
605> **Figure 1:** Figure description
606> GENERATED IMAGE SHOWN HERE
607>
608> **Figure 2:** Animated figure that spins to show all faces.
609> GENERATED IMAGE SHOWN HERE
610>
611> **Figure 3:**
612> GENERATED IMAGE OF CUBE SHOWN HERE
613>
614> **Figure 4:**
615> GENERATED IMAGE OF CYLINDER SHOWN HERE
616>
617> **Figure 5:**
618> GENERATED IMAGE OF SPHERE SHOWN HERE
619
620The metadata of the Figure block can contain various directives to alter how
621the image will be generated. These can be comma separated to give multiple
622metadata directives:
623
624- `NORENDER`: Don't generate an image for this example, but show the example text.
625- `Hide`: Generate, but don't show script or image. This can be used to generate images to be manually displayed in markdown text blocks.
626- `2D`: Orient camera in a top-down view for showing 2D objects.
627- `3D`: Orient camera in an oblique view for showing 3D objects.
628- `VPD=440`: Force viewpoint distance `$vpd` to 440.
629- `VPT=[10,20,30]` Force the viewpoint translation `$vpt` to `[10,20,30]`.
630- `VPR=[55,0,600]` Force the viewpoint rotation `$vpr` to `[55,0,60]`.
631- `Spin`: Animate camera orbit around the `[0,1,1]` axis to display all sides of an object.
632- `FlatSpin`: Animate camera orbit around the Z axis, above the XY plane.
633- `Anim`: Make an animation where `$t` varies from `0.0` to almost `1.0`.
634- `Frames=36`: Number of animation frames to make.
635- `FrameMS=250`: Sets the number of milliseconds per frame for spins and animation.
636- `Small`: Make the image small sized.
637- `Med`: Make the image medium sized.
638- `Big`: Make the image big sized.
639- `Huge`: Make the image huge sized.
640- `Size=880x640`: Make the image 880 by 640 pixels in size.
641- `ThrownTogether`: Render in Thrown Together view mode instead of Preview mode.
642- `Render`: Force full rendering from OpenSCAD, instead of the normal Preview mode.
643- `Edges`: Highlight face edges.
644- `NoAxes`: Hides the axes and scales.
645- `NoScales`: Hides the scale numbers along the axes.
646- `ScriptUnder`: Display script text under image, rather than beside it.
647
648
649Example Block
650-------------
651
652An Example block shows a script, and possibly shows an image generated from it.
653The script is in the multi-line body. The `Examples` (plural) block does
654the same, but it treats eash body line as a separate Example bloc to show.
655Any images, if generated, will be created by running it in OpenSCAD:
656
657 // Example: Example description
658 // cylinder(h=100, d1=75, d2=50);
659 // up(100) cylinder(h=100, d1=50, d2=75);
660 // Example(Spin,VPD=444): Animated shape that spins to show all faces.
661 // cube([10,100,50], center=true);
662 // cube([100,10,30], center=true);
663 // Examples:
664 // cube(100);
665 // cylinder(h=100,d=50);
666 // sphere(d=100);
667
668Which outputs Markdown code that renders like:
669
670> **Example 1:** Example description
671> ```openscad
672> cylinder(h=100, d1=75, d2=50);
673> up(100) cylinder(h=100, d1=50, d2=75);
674> ```
675> GENERATED IMAGE SHOWN HERE
676>
677> **Example 2:** Animated shape that spins to show all faces.
678> ```openscad
679> cube([10,100,50], center=true);
680> cube([100,10,30], center=true);
681> ```
682> GENERATED IMAGE SHOWN HERE
683>
684> **Example 3:**
685> ```openscad
686> cube(100);
687> ```
688> GENERATED IMAGE OF CUBE SHOWN HERE
689>
690> **Example 4:**
691> ```openscad
692> cylinder(h=100,d=50);
693> ```
694> GENERATED IMAGE OF CYLINDER SHOWN HERE
695>
696> **Example 5:**
697> ```openscad
698> sphere(d=100);
699> ```
700> GENERATED IMAGE OF SPHERE SHOWN HERE
701
702The metadata of the Example block can contain various directives to alter how
703the image will be generated. These can be comma separated to give multiple
704metadata directives:
705
706- `NORENDER`: Don't generate an image for this example, but show the example text.
707- `Hide`: Generate, but don't show script or image. This can be used to generate images to be manually displayed in markdown text blocks.
708- `2D`: Orient camera in a top-down view for showing 2D objects.
709- `3D`: Orient camera in an oblique view for showing 3D objects. Often used to force an Example sub-block to generate an image in Function and Constant blocks.
710- `VPD=440`: Force viewpoint distance `$vpd` to 440.
711- `VPT=[10,20,30]` Force the viewpoint translation `$vpt` to `[10,20,30]`.
712- `VPR=[55,0,600]` Force the viewpoint rotation `$vpr` to `[55,0,60]`.
713- `Spin`: Animate camera orbit around the `[0,1,1]` axis to display all sides of an object.
714- `FlatSpin`: Animate camera orbit around the Z axis, above the XY plane.
715- `Anim`: Make an animation where `$t` varies from `0.0` to almost `1.0`.
716- `FrameMS=250`: Sets the number of milliseconds per frame for spins and animation.
717- `Frames=36`: Number of animation frames to make.
718- `Small`: Make the image small sized.
719- `Med`: Make the image medium sized.
720- `Big`: Make the image big sized.
721- `Huge`: Make the image huge sized.
722- `Size=880x640`: Make the image 880 by 640 pixels in size.
723- `Render`: Force full rendering from OpenSCAD, instead of the normal preview.
724- `Edges`: Highlight face edges.
725- `NoAxes`: Hides the axes and scales.
726- `ScriptUnder`: Display script text under image, rather than beside it.
727
728Modules will default to generating and displaying the image as if the `3D`
729directive is given. Functions and constants will default to not generating
730an image unless `3D`, `Spin`, `FlatSpin` or `Anim` is explicitly given.
731
732If any lines of the Example script begin with `--`, then they are not shown in
733the example script output to the documentation, but they *are* included in the
734script used to generate the example image, without the `--`, of course:
735
736 // Example: Multi-line example.
737 // --$fn = 72; // Lines starting with -- aren't shown in docs example text.
738 // lst = [
739 // "multi-line examples",
740 // "are shown in one block",
741 // "with a single image.",
742 // ];
743 // foo(lst, 23, "blah");
744
745
746Creating Custom Block Headers
747=============================
748
749If you have need of a non-standard documentation block in your docs, you can declare the new block type using `DefineHeader:`. This has the syntax:
750
751 // DefineHeader(TYPE): NEWBLOCKNAME
752
753or:
754
755 // DefineHeader(TYPE;OPTIONS): NEWBLOCKNAME
756
757Where NEWBLOCKNAME is the name of the new block header, OPTIONS is an optional list of zero or more semicolon-separated header options, and TYPE defines the behavior of the new block. TYPE can be one of:
758
759- `Generic`: Show both the TitleText and body.
760- `Text`: Show the TitleText as the first line of the body.
761- `Headerless`: Show the TitleText as the first line of the body, with no header line.
762- `Label`: Show only the TitleText and no body.
763- `NumList`: Shows TitleText, and the body lines in a numbered list.
764- `BulletList`: Shows TitleText, and the body lines in a bullet list.
765- `Table`: Shows TitleText, and body lines in a definition table.
766- `Figure`: Shows TitleText, and an image rendered from the script in the Body.
767- `Example`: Like Figure, but also shows the body as an example script.
768
769The OPTIONS are zero or more semicolon separated options for defining the header options. Some of them only require the option name, like `Foo`, and some have an option name and a value separated by an equals sign, like `Foo=Bar`. There is currently only one option common to all header types:
770
771- `ItemOnly`: Specify that the new header is only allowed as part of the documentation block for a Constant, Function, or Module.
772
773Generic Block Type
774------------------
775
776The Generic block header type takes both title and body lines and generates a markdown block that has the block header, title, and a following body:
777
778 // DefineHeader(Generic): Result
779 // Result: For Typical Cases
780 // Does typical things.
781 // Or something like that.
782 // Refer to {{stuff()}} for more info.
783 // Result: For Atypical Cases
784 // Performs an atypical thing.
785
786Which outputs Markdown code that renders like:
787
788> **Result:** For Typical Cases
789>
790> Does typical things.
791> Or something like that.
792> Refer to [stuff()](foobar.scad#function-stuff) for more info.
793>
794> **Result:** For Atypical Cases
795>
796> Performs an atypical thing.
797>
798
799
800Text Block Type
801---------------
802
803The Text block header type is similar to the Generic type, except it merges the title into the body. This is useful for allowing single-line or multi-line blocks:
804
805 // DefineHeader(Text): Reason
806 // Reason: This is a simple reason.
807 // Reason: This is a complex reason.
808 // It is a multi-line explanation
809 // about why this does what it does.
810 // Refer to {{nonsense()}} for more info.
811
812Which outputs Markdown code that renders like:
813
814> **Reason:**
815>
816> This is a simple reason.
817>
818> **Reason:**
819>
820> This is a complex reason.
821> It is a multi-line explanation
822> about why this does what it does.
823> Refer to [nonsense()](foobar.scad#function-nonsense) for more info.
824>
825
826Headerless Block Type
827---------------------
828
829The Headerless block header type is similar to the Generic type, except it merges the title into the body, and generates no header line.
830
831 // DefineHeader(Headerless): Explanation
832 // Explanation: This is a simple explanation.
833 // Explanation: This is a complex explanation.
834 // It is a multi-line explanation
835 // about why this does what it does.
836 // Refer to {{nonsense()}} for more info.
837
838Which outputs Markdown code that renders like:
839
840> This is a simple explanation.
841>
842> This is a complex explanation.
843> It is a multi-line explanation
844> about why this does what it does.
845> Refer to [nonsense()](foobar.scad#function-nonsense) for more info.
846>
847
848
849Label Block Type
850----------------
851
852The Label block header type takes just the title, and shows it with the header:
853
854 // DefineHeader(Label): Regions
855 // Regions: Antarctica, New Zealand
856 // Regions: Europe, Australia
857
858Which outputs Markdown code that renders like:
859
860> **Regions:** Antarctica, New Zealand
861> **Regions:** Europe, Australia
862
863
864NumList Block Type
865------------------
866
867The NumList block header type takes both title and body lines, and outputs a
868numbered list block:
869
870 // DefineHeader(NumList): Steps
871 // Steps: How to handle being on fire.
872 // Stop running around and panicing.
873 // Drop to the ground. Refer to {{drop()}}.
874 // Roll on the ground to smother the flames.
875
876Which outputs Markdown code that renders like:
877
878> **Steps:** How to handle being on fire.
879>
880> 1. Stop running around and panicing.
881> 2. Drop to the ground. Refer to [drop()](foobar.scad#function-drop).
882> 3. Roll on the ground to smother the flames.
883>
884
885
886BulletList Block Type
887---------------------
888
889The BulletList block header type takes both title and body lines:
890
891 // DefineHeader(BulletList): Side Effects
892 // Side Effects: For Typical Uses
893 // The variable {{$foo}} gets set.
894 // The default for subsequent calls is updated.
895
896Which outputs Markdown code that renders like:
897
898> **Side Effects:** For Typical Uses
899>
900> - The variable [$foo](foobar.scad#function-foo) gets set.
901> - The default for subsequent calls is updated.
902>
903
904
905Table Block Type
906----------------
907
908The Table block header type outputs a header block with the title, followed by one or more tables. This is generally meant for definition lists. The header names are given as the `Headers=` option in the DefineHeader metadata. Header names are separated by `|` (vertical bar, or pipe) characters, and sets of headers (for multiple tables) are separated by `||` (two vertical bars). A header that starts with the `^` (hat, or circumflex) character, will cause the items in that column to be surrounded by \`foo\` literal markers. Cells in the body content are separated by `=` (equals signs):
909
910 // DefineHeader(Table;Headers=^Link Name|Description): Anchors
911 // Anchors: by Name
912 // "link1" = Anchor for the joiner Located at the {{BACK}} side of the shape.
913 // "a"/"b" = Anchor for the joiner Located at the {{FRONT}} side of the shape.
914
915Which outputs Markdown code that renders like:
916
917> **Anchors:** by Name
918>
919> Link Name | Description
920> -------------- | --------------------
921> `"link1"` | Anchor for the joiner at the [BACK](constants.scad#constant-back) side of the shape.
922> `"a"` / `"b"` | Anchor for the joiner at the [FRONT](constants.scad#constant-front) side of the shape.
923>
924
925You can have multiple subtables, separated by a line with only three dashes: `---`:
926
927 // DefineHeader(Table;Headers=^Pos Arg|What it Does||^Names Arg|What it Does): Args
928 // Args:
929 // foo = The foo argument.
930 // bar = The bar argument.
931 // ---
932 // baz = The baz argument.
933 // qux = The baz argument.
934
935Which outputs Markdown code that renders like:
936
937> **Args:**
938>
939> Pos Arg | What it Does
940> ----------- | --------------------
941> `foo` | The foo argument.
942> `bar` | The bar argument.
943>
944> Named Arg | What it Does
945> ----------- | --------------------
946> `baz` | The baz argument.
947> `qux` | The qux argument.
948>
949
950
951Defaults Configuration
952======================
953
954The `openscad_decsgen` script looks for an `.openscad_docsgen_rc` file in the source code directory it is run in. In that file, you can give a few defaults for what files will be processed, and where to save the generated documentation.
955
956---
957
958To specify what directory to write the output documentation to, you can use the DocsDirectory block:
959
960 DocsDirectory: wiki_dir
961
962---
963
964To specify what target profile to output for, use the TargetProfile block. You must specify either `wiki` or `githubwiki` as the value:
965
966 TargetProfile: githubwiki
967
968---
969
970To specify what the project name is, use the ProjectName block, like this:
971
972 ProjectName: My Project Name
973
974---
975
976To specify what types of files will be generated, you can use the GenerateDocs block. You give it a comma separated list of docs file types like this:
977
978 GenerateDocs: Files, ToC, Index, Topics, CheatSheet, Sidebar
979
980Where the valid docs file types are as follows:
981
982- `Files`: Generate a documentation file for each .scad input file. Generates Images.
983- `ToC`: Generate a project-wide Table of Contents file.
984- `Index`: Generate an alphabetically sorted function/module/constants index file.
985- `Topics`: Generate an index file of topics, sorted alphabetically.
986- `CheatSheet`: Generate a CheatSheet summary of function/module Usages.
987- `Cheat`: The same as `CheatSheet`.
988- `Sidebar`: Generate a \_Sidebar index of files.
989
990---
991
992To ignore specific files, to prevent generating documentation for them, you can use the IgnoreFiles block. Note that the commentline prefix is not needed in the configuration file:
993
994 IgnoreFiles:
995 ignored1.scad
996 ignored2.scad
997 tmp_*.scad
998
999---
1000
1001To prioritize the ordering of files when generating the Table of Contents and other indices, you can use the PrioritizeFiles block:
1002
1003 PrioritizeFiles:
1004 file1.scad
1005 file2.scad
1006
1007---
1008
1009You can also use the DefineHeader block in the config file to make custom block headers:
1010
1011 DefineHeader(Text;ItemOnly): Returns
1012 DefineHeader(BulletList): Side Effects
1013 DefineHeader(Table;Headers=^Anchor Name|Position): Extra Anchors
1014
1015
1016