Finished importers-exporters documentation
This commit is contained in:
@ -8,7 +8,7 @@ Introduction
|
||||
============
|
||||
|
||||
The purpose of this section is to explain how to import external file formats into CadQuery, and export files from
|
||||
it as well. While the external file formats can be used to interchange CAD model data with out software, CadQuery
|
||||
it as well. While the external file formats can be used to interchange CAD model data with other software, CadQuery
|
||||
does not support any formats that carry parametric data with them at this time. The only format that is fully
|
||||
parametric is CadQuery's own Python format. Below are lists of the import and export file formats that CadQuery
|
||||
supports.
|
||||
@ -33,21 +33,21 @@ Export Formats
|
||||
Notes on the Formats
|
||||
#######################
|
||||
|
||||
* DXF is useful for importing complex 2D profiles that would be tedious to create using CadQuery's 2D operations. An example is that the 2D profiles of aluminum extrusion are often provided in DXF format. This can be imported and extruded to create the length of extrusion that is needed in a design.
|
||||
* STEP files are useful for interchanging model data with other CAD and analysis systems, such as FreeCAD.
|
||||
* STL and AMF files are mesh-based formats which are typically used in additive manufacturing (i.e. 3D printing). AMF files support more features, but are not as widely supported as STL files.
|
||||
* TJS is short for ThreeJS, and is a JSON format that is useful for displaying 3D models in web browsers. The TJS format is used to display embedded 3D examples within the CadQuery documentation.
|
||||
* VRML is a format for representing interactive 3D objects in a web browser.
|
||||
* DXF is useful for importing complex 2D profiles that would be tedious to create using CadQuery's 2D operations. An example is that the 2D profiles of aluminum extrusion are often provided in DXF format. These can be imported and extruded to create the length of extrusion that is needed in a design.
|
||||
* STEP files are useful for interchanging model data with other CAD and analysis systems, such as FreeCAD. Many parts such as screws have STEP files available, which can be imported and used in CadQuery assemblies.
|
||||
* STL and AMF files are mesh-based formats which are typically used in additive manufacturing (i.e. 3D printing). AMF files support more features, but are not as universally supported as STL files.
|
||||
* TJS is short for ThreeJS, and is a JSON mesh format that is useful for displaying 3D models in web browsers. The TJS format is used to display embedded 3D examples within the CadQuery documentation.
|
||||
* VRML is a mesh-based format for representing interactive 3D objects in a web browser.
|
||||
|
||||
Importing DXF
|
||||
##############
|
||||
|
||||
DXF files can be imported using the :py:meth:`importers.importDXF` method. There are 3 parameters that can be
|
||||
passed this method to control how the DXF is handled.
|
||||
passed to this method to control how the DXF is handled.
|
||||
|
||||
* *fileName* - The path and name of the DXF file to be imported.
|
||||
* *tol* - The tolerance used for merging edges into wires (default: 1e-6).
|
||||
* *exclude* - A list of layer names not to import (default: []).
|
||||
* ``fileName`` - The path and name of the DXF file to be imported.
|
||||
* ``tol`` - The tolerance used for merging edges into wires (default: 1e-6).
|
||||
* ``exclude`` - A list of layer names not to import (default: []).
|
||||
|
||||
Importing a DXF profile with default settings and using it within a CadQuery script is shown in the following code.
|
||||
|
||||
@ -62,7 +62,7 @@ Importing a DXF profile with default settings and using it within a CadQuery scr
|
||||
)
|
||||
|
||||
Note the use of the :py:meth:`Workplane.wires` and :py:meth:`Workplane.toPending` methods to make the DXF profile
|
||||
ready for use during subsequent operations. Calling toPending() tells CadQuery to make the edges/wires available
|
||||
ready for use during subsequent operations. Calling ``toPending()`` tells CadQuery to make the edges/wires available
|
||||
to the next operation that is called in the chain.
|
||||
|
||||
Importing STEP
|
||||
@ -80,7 +80,7 @@ There are no parameters for this method other than the file path to import.
|
||||
Exporting SVG
|
||||
##############
|
||||
|
||||
The SVG exporter has several options which can be useful for getting the desired final output. Those
|
||||
The SVG exporter has several options which can be useful for achieving the desired final output. Those
|
||||
options are as follows.
|
||||
|
||||
* *width* - Document width of the resulting image.
|
||||
@ -95,7 +95,7 @@ options are as follows.
|
||||
* *showHidden* - Whether or not to show hidden lines.
|
||||
|
||||
The options are passed to the exporter in a dictionary, and can be left out to force the SVG to be created with default options.
|
||||
Below are a few examples.
|
||||
Below are examples with and without options set.
|
||||
|
||||
Without options:
|
||||
|
||||
@ -115,7 +115,7 @@ Results in:
|
||||
Note that the exporters API figured out the format type from the file extension. The format
|
||||
type can be set explicitly by using :py:class:`exporters.ExportTypes`.
|
||||
|
||||
The following is an example of using options to alter the resulting SVG output by passing in the opt parameter.
|
||||
The following is an example of using options to alter the resulting SVG output by passing in the ``opt`` parameter.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@ -148,11 +148,116 @@ Which results in the following image:
|
||||
Exporting STL
|
||||
##############
|
||||
|
||||
The STL exporter is capable of adjusting the quality of the resulting STL, and accepts the following options.
|
||||
The STL exporter is capable of adjusting the quality of the resulting mesh, and accepts the following parameters.
|
||||
|
||||
* *fileName* - The path and file name to write the STL output to.
|
||||
* *tolerance* -
|
||||
* *angularTolerance* -
|
||||
* ``fileName`` - The path and file name to write the STL output to.
|
||||
* ``tolerance`` - A linear deflection setting which limits the distance between a curve and its tessellation. Setting this value too low will result in large meshes that can consume computing resources. Setting the value too high can result in meshes with a level of detail that is too low. Default is 0.1, which is good starting point for a range of cases.
|
||||
* ``angularTolerance`` - Angular deflection setting which limits the angle between subsequent segments in a polyline. Default is 0.1.
|
||||
|
||||
For more complex objects, some experimentation with ``tolerance`` and ``angularTolerance`` may be required to find the
|
||||
optimum values that will produce an acceptable mesh.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import cadquery as cq
|
||||
from cadquery import exporters
|
||||
|
||||
result = cq.Workplane().box(10, 10, 10)
|
||||
|
||||
exporters.export(result, '/path/to/file/mesh.stl')
|
||||
|
||||
Exporting AMF
|
||||
##############
|
||||
|
||||
The AMF exporter is capable of adjusting the quality of the resulting mesh, and accepts the following parameters.
|
||||
|
||||
* ``fileName`` - The path and file name to write the AMF output to.
|
||||
* ``tolerance`` - A linear deflection setting which limits the distance between a curve and its tessellation. Setting this value too low will result in large meshes that can consume computing resources. Setting the value too high can result in meshes with a level of detail that is too low. Default is 0.1, which is good starting point for a range of cases.
|
||||
* ``angularTolerance`` - Angular deflection setting which limits the angle between subsequent segments in a polyline. Default is 0.1.
|
||||
|
||||
For more complex objects, some experimentation with ``tolerance`` and ``angularTolerance`` may be required to find the
|
||||
optimum values that will produce an acceptable mesh. Note that parameters for AMF color and material are absent.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import cadquery as cq
|
||||
from cadquery import exporters
|
||||
|
||||
result = cq.Workplane().box(10, 10, 10)
|
||||
|
||||
exporters.export(result, '/path/to/file/mesh.amf', tolerance=0.01, angularTolerance=0.1)
|
||||
|
||||
|
||||
Exporting TJS
|
||||
##############
|
||||
|
||||
The TJS (ThreeJS) exporter is capable of adjusting the quality of the resulting JSON-based mesh, and accepts the following parameters.
|
||||
|
||||
* ``fileName`` - The path and file name to write the ThreeJS output to.
|
||||
* ``tolerance`` - A linear deflection setting which limits the distance between a curve and its tessellation. Setting this value too low will result in large meshes that can consume computing resources. Setting the value too high can result in meshes with a level of detail that is too low. Default is 0.1, which is good starting point for a range of cases.
|
||||
* ``angularTolerance`` - Angular deflection setting which limits the angle between subsequent segments in a polyline. Default is 0.1.
|
||||
|
||||
For more complex objects, some experimentation with ``tolerance`` and ``angularTolerance`` may be required to find the
|
||||
optimum values that will produce an acceptable mesh.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import cadquery as cq
|
||||
from cadquery import exporters
|
||||
|
||||
result = cq.Workplane().box(10, 10, 10)
|
||||
|
||||
exporters.export(result, '/path/to/file/mesh.json', tolerance=0.01, angularTolerance=0.1, exportType=exporters.ExportTypes.TJS)
|
||||
|
||||
Note that the export type was explicitly specified as ``TJS`` because the extension that was used for the file name was ``.json``. If the extension ``.tjs``
|
||||
had been used, CadQuery would have understood to use the ``TJS`` export format.
|
||||
|
||||
Exporting VRML
|
||||
###############
|
||||
|
||||
The VRML exporter is capable of adjusting the quality of the resulting mesh, and accepts the following parameters.
|
||||
|
||||
* ``fileName`` - The path and file name to write the VRML output to.
|
||||
* ``tolerance`` - A linear deflection setting which limits the distance between a curve and its tessellation. Setting this value too low will result in large meshes that can consume computing resources. Setting the value too high can result in meshes with a level of detail that is too low. Default is 0.1, which is good starting point for a range of cases.
|
||||
* ``angularTolerance`` - Angular deflection setting which limits the angle between subsequent segments in a polyline. Default is 0.1.
|
||||
|
||||
For more complex objects, some experimentation with ``tolerance`` and ``angularTolerance`` may be required to find the
|
||||
optimum values that will produce an acceptable mesh.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import cadquery as cq
|
||||
from cadquery import exporters
|
||||
|
||||
result = cq.Workplane().box(10, 10, 10)
|
||||
|
||||
exporters.export(result, '/path/to/file/mesh.vrml', tolerance=0.01, angularTolerance=0.1)
|
||||
|
||||
Exporting Other Formats
|
||||
########################
|
||||
|
||||
The remaining export formats do not accept any additional parameters other than file name, and can be exported
|
||||
using the following structure.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import cadquery as cq
|
||||
from cadquery import exporters
|
||||
|
||||
result = cq.Workplane().box(10, 10, 10)
|
||||
|
||||
exporters.export(result, '/path/to/file/object.[file_extension]')
|
||||
|
||||
Be sure to use the correct file extension so that CadQuery can determine the export format. If in doubt, fall
|
||||
back to setting the type explicitly by using :py:class:`exporters.ExportTypes`.
|
||||
|
||||
For example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import cadquery as cq
|
||||
from cadquery import exporters
|
||||
|
||||
result = cq.Workplane().box(10, 10, 10)
|
||||
|
||||
exporters.export(result, '/path/to/file/object.dxf', exporters.ExportTypes.DXF)
|
||||
|
Reference in New Issue
Block a user