Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openscad-docsgen

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openscad-docsgen

A processor to generate Markdown code documentation with images from OpenSCAD source comments.

  • 2.0.44
  • PyPI
  • Socket score

Maintainers
1

################################ OpenSCAD Documentation Generator ################################

This package generates wiki-ready GitHub flavored markdown documentation pages from in-line source code comments. This is similar to Doxygen or JavaDoc, but designed for use with OpenSCAD code. Example images can be generated automatically from short example scripts.

Documentation about how to add documentation comments to OpenSCAD code can be found at https://github.com/revarbat/openscad_docsgen/blob/main/WRITING_DOCS.md

Installing openscad-docsgen

The easiest way to install this is to use pip::

% pip3 install openscad_docsgen

To install directly from these sources, you can instead do::

% python3 setup.py build install

Using openscad-docsgen

The simplest way to generate documentation is::

% openscad-docsgen -m *.scad

Which will read all of .scad files in the current directory, and writes out documentation for each .scad file to the ./docs/ dir. To write out to a different directory, use the -D argument::

% openscad-docsgen -D wikidir -m *.scad

To write out an alphabetical function/module index markdown file, use the -i flag::

% openscad-docsgen -i *.scad

To write out a Table of Contents markdown file, use the -t flag::

% openscad-docsgen -t *.scad

To write out a CheatSheet markdown file, use the -c flag. In addition, you can specify the project name shown in the CheatSheet with the -P PROJECTNAME argument::

% openscad-docsgen -c -P "My Foobar Library" *.scad

A Topics index file can be generated by passing the -I flag::

% openscad-docsgen -I *.scad

You can just test for script errors more quickly with the -T flag (for test-only)::

% openscad-docsgen -m -T *.scad

By default, the target output profile is to generate documentation for a GitHub Wiki. You can output for a more generic Wiki with -p wiki::

% openscad-docsgen -ticmI -p wiki *.scad

Docsgen Configuration File

You can also make more persistent configurations by putting a .openscad_docsgen_rc file in the directory you will be running openscad-docsgen from. It can look something like this::

DocsDirectory: WikiDir/
TargetProfile: githubwiki
ProjectName: The Foobar Project
GeneratedDocs: Files, ToC, Index, Topics, CheatSheet
SidebarHeader:
  ## Indices
  .
SidebarMiddle:
  [Tutorials](Tutorials)  
IgnoreFiles:
  foo.scad
  std.scad
  version.scad
  tmp_*.scad
PrioritizeFiles:
  First.scad
  Second.scad
  Third.scad
  Fourth.scad
DefineHeader(BulletList): Side Effects
DefineHeader(Table;Headers=Anchor Name|Position): Extra Anchors

For an explanation of the syntax and the specific headers, see: https://github.com/revarbat/openscad_docsgen/blob/main/WRITING_DOCS.md

Using openscad-mdimggen

If you have MarkDown based files that you would like to generate images for, you can use the openscad_mdimggen command. It can take the following arguments::

-h, --help            Show help message and exit
-D DOCS_DIR, --docs-dir DOCS_DIR
                      The directory to put generated documentation in.
-P FILE_PREFIX, --file-prefix FILE_PREFIX
                      The prefix to put in front of each output markdown file.
-T, --test-only       If given, don't generate images, but do try executing the scripts.
-I IMAGE_ROOT, --image_root IMAGE_ROOT
                      The directory to put generated images in.
-f, --force           If given, force regeneration of images.
-a, --png-animation   If given, animations are created using animated PNGs instead of GIFs.

What openscad-mdimggen will do is read the input MarkDown file and look for fenced scripts of OpenSCAD code, that starts with a line of the form::

```openscad-METADATA

It will copy all non-script lines to the output markdown file, and run OpenSCAD for each of the found fenced scripts, inserting the generated image into the output MarkDown file after the script block. The METADATA for each script will define the viewpoint and other info for the given generated image. This METADATA takes the form of a set of semi-colon separated options that can be any of the following:

  • NORENDER: Don't generate an image for this example, but show the example text.
  • ImgOnly: Generate and show the image, but hide the text of the script.
  • Hide: Generate, but don't show script or image. This can be used to generate images to be manually displayed in markdown text blocks.
  • 2D: Orient camera in a top-down view for showing 2D objects.
  • 3D: Orient camera in an oblique view for showing 3D objects.
  • VPT=[10,20,30] Force the viewpoint translation $vpt to [10,20,30].
  • VPR=[55,0,600] Force the viewpoint rotation $vpr to [55,0,60].
  • VPD=440: Force viewpoint distance $vpd to 440.
  • VPF=22.5: Force field of view angle $vpf to 22.5.
  • Spin: Animate camera orbit around the [0,1,1] axis to display all sides of an object.
  • FlatSpin: Animate camera orbit around the Z axis, above the XY plane.
  • Anim: Make an animation where $t varies from 0.0 to almost 1.0.
  • FrameMS=250: Sets the number of milliseconds per frame for spins and animation.
  • FPS=8: Sets the number of frames per second for spins and animation.
  • Frames=36: Number of animation frames to make.
  • Small: Make the image small sized.
  • Med: Make the image medium sized.
  • Big: Make the image big sized.
  • Huge: Make the image huge sized.
  • Size=880x640: Make the image 880 by 640 pixels in size.
  • Render: Force full rendering from OpenSCAD, instead of the normal preview.
  • Edges: Highlight face edges.
  • NoAxes: Hides the axes and scales.
  • NoScales: Hides the scale numbers along the axes.
  • ColorScheme: Generate the image using a specific color scheme
    • Usage: ColorScheme=<color scheme name> (e.g. ColorScheme=BeforeDawn)
    • Default color scheme: Cornfield
    • Predefined color schemes: Cornfield, Metallic, Sunset, Starnight, BeforeDawn, Nature, DeepOcean, Solarized, Tomorrow, Tomorrow Night, Monotone
    • Color schemes defined as a Read-only Resource or User Resource are also supported.

For example::

```openscad-FlatSpin;VPD=500
prismoid([60,40], [40,20], h=40, offset=[10,10]);
```

Will generate an animated flat spin of the prismoid at a viewing distance of 500. While::

```openscad-3D;Big
prismoid([60,40], [40,20], h=40, offset=[10,10]);
```

Will generate a still image of the same prismoid, but at a bigger image size.

MDImgGen Configuration File

You can store defaults for openscad_mdimggen in the .openscad_mdimggen_rc file like this::

docs_dir: "BOSL2.wiki"
image_root: "images/tutorials"
file_prefix: "Tutorial-"
source_files: "tutorials/*.md"
png_animations: true

External Calling

Here's an example of how to use this library, to get the parsed documentation data::

import openscad_docsgen as docsgen
from glob import glob
from pprint import pprint
dgp = docsgen.DocsGenParser(quiet=True)
dgp.parse_files(glob("*.scad"))
for name in dgp.get_indexed_names():
    data = dgp.get_indexed_data(name)
    pprint(name)
    pprint(data["description"])

The data for an OpenSCAD function, module, or constant generally looks like::

{
    'name': 'Function&Module',  // Could also be 'Function', 'Module', or 'Constant'
    'subtitle': 'line_of()',
    'body': [],
    'file': 'distributors.scad',
    'line': 43,
    'aliases': ['linear_spread()'],
    'topics': ['Distributors'],
    'usages': [
        {
            'subtitle': 'Spread `n` copies by a given spacing',
            'body': ['line_of(spacing, <n>, <p1=>) ...']
        },
        {
            'subtitle': 'Spread copies every given spacing along the line',
            'body': ['line_of(spacing, <l=>, <p1=>) ...']
        },
        {
            'subtitle': 'Spread `n` copies along the length of the line',
            'body': ['line_of(<n=>, <l=>, <p1=>) ...']
        },
        {
            'subtitle': 'Spread `n` copies along the line from `p1` to `p2`',
            'body': ['line_of(<n=>, <p1=>, <p2=>) ...']
        },
        {
            'subtitle': 'Spread copies every given spacing, centered along the line from `p1` to `p2`',
            'body': ['line_of(<spacing>, <p1=>, <p2=>) ...']
        },
        {
            'subtitle': 'As a function',
            'body': [
                'pts = line_of(<spacing>, <n>, <p1=>);',
                'pts = line_of(<spacing>, <l=>, <p1=>);',
                'pts = line_of(<n=>, <l=>, <p1=>);',
                'pts = line_of(<n=>, <p1=>, <p2=>);',
                'pts = line_of(<spacing>, <p1=>, <p2=>);'
            ]
        }
    ],
    'description': [
        'When called as a function, returns a list of points at evenly spread positions along a line.',
        'When called as a module, copies `children()` at one or more evenly spread positions along a line.',
        'By default, the line will be centered at the origin, unless the starting point `p1` is given.',
        'The line will be pointed towards `RIGHT` (X+) unless otherwise given as a vector in `l`,',
        '`spacing`, or `p1`/`p2`.',
    ],
    'arguments': [
        'spacing = The vector giving both the direction and spacing distance between each set of copies.',
        'n = Number of copies to distribute along the line. (Default: 2)',
        '---',
        'l = Either the scalar length of the line, or a vector giving both the direction and length of the line.',
        'p1 = If given, specifies the starting point of the line.',
        'p2 = If given with `p1`, specifies the ending point of line, and indirectly calculates the line length.'
    ],
    'see_also': ['xcopies()', 'ycopies()'],
    'examples': [
        ['line_of(10) sphere(d=1);'],
        ['line_of(10, n=5) sphere(d=1);'],
        ['line_of([10,5], n=5) sphere(d=1);'],
        ['line_of(spacing=10, n=6) sphere(d=1);'],
        ['line_of(spacing=[10,5], n=6) sphere(d=1);'],
        ['line_of(spacing=10, l=50) sphere(d=1);'],
        ['line_of(spacing=10, l=[50,30]) sphere(d=1);'],
        ['line_of(spacing=[10,5], l=50) sphere(d=1);'],
        ['line_of(l=50, n=4) sphere(d=1);'],
        ['line_of(l=[50,-30], n=4) sphere(d=1);'],
        [
            'line_of(p1=[0,0,0], p2=[5,5,20], n=6) '
            'cube(size=[3,2,1],center=true);'
        ],
        [
            'line_of(p1=[0,0,0], p2=[5,5,20], spacing=6) '
            'cube(size=[3,2,1],center=true);'
        ],
        [
            'line_of(l=20, n=3) {',
            '    cube(size=[1,3,1],center=true);',
            '    cube(size=[3,1,1],center=true);',
            '}'
        ],
        [
            'pts = line_of([10,5],n=5);',
            'move_copies(pts) circle(d=2);'
        ]
    ],
    'children': [
        {
            'name': 'Side Effects',
            'subtitle': '',
            'body': [
                '`$pos` is set to the relative centerpoint of each child copy.',
                '`$idx` is set to the index number of each child being copied.'
            ],
            'file': 'distributors.scad',
            'line': 88
        }
    ]
}

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc