Import / Export

Part and Assembly instances can be exported to file, and created by importing from file.

For any of the importers or exporters below,

Getting an Exporter

An exporter will get an existing Part or Assembly and write it to file.

An Exporter can be instantiated from a Part or Assembly instance with the use of exporter().

For example, exporting a .json file may be done with:

>>> from cqparts_misc.basic.primatives import Cube
>>> cube = Cube(size=2)

>>> json_exporter = cube.exporter('json')
>>> json_exporter('my_cube.json')  

>>> # or in a single line
>>> cube.exporter('json')('my_cube.json')  

each Exporter will have different ways to call it, and different parameters.

Getting an Importer

Importers create a new instance of a Part or Assembly from the data in the file being imported.

So an Importer is instantiated from Part or Assembly class (not an instance of that class).

For example, importing a .STEP file may be achieved with:

>>> from cqparts import Part

>>> step_importer = Part.importer('step')
>>> my_part = step_importer('my_file.step')  

>>> # or in a single line
>>> my_part = Part.importer('step')('my_file.step')  

each Importer will have different ways to call it, and different parameters.

To use a specific importer, please find it in the cqparts.codec module and read its documentation; each one should have examples.


Formats are documented in their respective Importer and Exporter classes.

To learn more, have a look at the cqparts.codec module page.

Creating your own

If you’d like to create your own Exporter or Importer class, you can do it, and register it!

To learn more, look at the example code in register_exporter() and register_importer().