commands

Main PyGenCad entry point.

The commands sub-module provides helper functions for creating CommandFile and Layer objects targeting specific backends. Functions from the commands sub-module are available at the top level of the PyGenCAD package.

>>> from pygencad import *
>>> from StringIO import StringIO
>>> f = StringIO()
>>> with get_script(f, 'autocad') as script:
...     script.cmd("Hello, World!")
...
'l'
>>> "Hello, World!" in f.getvalue()
True

variables

pygencad.backends

Mapping of backend names to backend modules.


pygencad.backext

Mapping of backend names to backend file extensions.


functions

pygencad.get_script(filelike, backend)[source]

Return an initialized CommandFile object for the requested backend.

>>> from pygencad import *
>>> from StringIO import StringIO
>>> f = StringIO()
>>> get_script(f, 'autocad')
<pygencad.autocad.CommandFile object at 0x...>
>>> get_script(f, 'spam')
Traceback (most recent call last):
    ...
ValueError: Unknown backend ...!
Parameters:
  • filelike (filelike) – An object with a write method.
  • backend (string) – Name of the backend to use, must be in pygencad.backends.
Raises:

ValueError if the provided name isn’t in pygencad.backends

Returns:

An instantiated CommandFile object for the indicated backend.


pygencad.get_layer(backend)[source]

Return the layer class for the indicated backend.

>>> from pygencad import *
>>> from StringIO import StringIO
>>> f = StringIO()
>>> get_layer('autocad') # Notice the return isn't an object:
<class 'pygencad.autocad.Layer'>
>>> get_script(f, 'spam')
Traceback (most recent call last):
    ...
ValueError: Unknown backend ...!
Parameters:backend (string) – Name of the backend to use, must be in pygencad.backends.
Raises:ValueError if the provided name isn’t in pygencad.backends
Returns:Layer class for the indicated backend.