Skip to content

Commit 622f59b

Browse files
committed
Finished importers-exporters documentation
1 parent 3b8ebf6 commit 622f59b

File tree

1 file changed

+123
-18
lines changed

1 file changed

+123
-18
lines changed

doc/importexport.rst

Lines changed: 123 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Introduction
88
============
99

1010
The purpose of this section is to explain how to import external file formats into CadQuery, and export files from
11-
it as well. While the external file formats can be used to interchange CAD model data with out software, CadQuery
11+
it as well. While the external file formats can be used to interchange CAD model data with other software, CadQuery
1212
does not support any formats that carry parametric data with them at this time. The only format that is fully
1313
parametric is CadQuery's own Python format. Below are lists of the import and export file formats that CadQuery
1414
supports.
@@ -33,21 +33,21 @@ Export Formats
3333
Notes on the Formats
3434
#######################
3535

36-
* 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.
37-
* STEP files are useful for interchanging model data with other CAD and analysis systems, such as FreeCAD.
38-
* 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.
39-
* 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.
40-
* VRML is a format for representing interactive 3D objects in a web browser.
36+
* 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.
37+
* 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.
38+
* 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.
39+
* 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.
40+
* VRML is a mesh-based format for representing interactive 3D objects in a web browser.
4141

4242
Importing DXF
4343
##############
4444

4545
DXF files can be imported using the :py:meth:`importers.importDXF` method. There are 3 parameters that can be
46-
passed this method to control how the DXF is handled.
46+
passed to this method to control how the DXF is handled.
4747

48-
* *fileName* - The path and name of the DXF file to be imported.
49-
* *tol* - The tolerance used for merging edges into wires (default: 1e-6).
50-
* *exclude* - A list of layer names not to import (default: []).
48+
* ``fileName`` - The path and name of the DXF file to be imported.
49+
* ``tol`` - The tolerance used for merging edges into wires (default: 1e-6).
50+
* ``exclude`` - A list of layer names not to import (default: []).
5151

5252
Importing a DXF profile with default settings and using it within a CadQuery script is shown in the following code.
5353

@@ -62,7 +62,7 @@ Importing a DXF profile with default settings and using it within a CadQuery scr
6262
)
6363
6464
Note the use of the :py:meth:`Workplane.wires` and :py:meth:`Workplane.toPending` methods to make the DXF profile
65-
ready for use during subsequent operations. Calling toPending() tells CadQuery to make the edges/wires available
65+
ready for use during subsequent operations. Calling ``toPending()`` tells CadQuery to make the edges/wires available
6666
to the next operation that is called in the chain.
6767

6868
Importing STEP
@@ -80,7 +80,7 @@ There are no parameters for this method other than the file path to import.
8080
Exporting SVG
8181
##############
8282

83-
The SVG exporter has several options which can be useful for getting the desired final output. Those
83+
The SVG exporter has several options which can be useful for achieving the desired final output. Those
8484
options are as follows.
8585

8686
* *width* - Document width of the resulting image.
@@ -95,7 +95,7 @@ options are as follows.
9595
* *showHidden* - Whether or not to show hidden lines.
9696

9797
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.
98-
Below are a few examples.
98+
Below are examples with and without options set.
9999

100100
Without options:
101101

@@ -115,7 +115,7 @@ Results in:
115115
Note that the exporters API figured out the format type from the file extension. The format
116116
type can be set explicitly by using :py:class:`exporters.ExportTypes`.
117117

118-
The following is an example of using options to alter the resulting SVG output by passing in the opt parameter.
118+
The following is an example of using options to alter the resulting SVG output by passing in the ``opt`` parameter.
119119

120120
.. code-block:: python
121121
@@ -148,11 +148,116 @@ Which results in the following image:
148148
Exporting STL
149149
##############
150150

151-
The STL exporter is capable of adjusting the quality of the resulting STL, and accepts the following options.
151+
The STL exporter is capable of adjusting the quality of the resulting mesh, and accepts the following parameters.
152152

153-
* *fileName* - The path and file name to write the STL output to.
154-
* *tolerance* -
155-
* *angularTolerance* -
153+
* ``fileName`` - The path and file name to write the STL output to.
154+
* ``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.
155+
* ``angularTolerance`` - Angular deflection setting which limits the angle between subsequent segments in a polyline. Default is 0.1.
156+
157+
For more complex objects, some experimentation with ``tolerance`` and ``angularTolerance`` may be required to find the
158+
optimum values that will produce an acceptable mesh.
159+
160+
.. code-block:: python
161+
162+
import cadquery as cq
163+
from cadquery import exporters
164+
165+
result = cq.Workplane().box(10, 10, 10)
166+
167+
exporters.export(result, '/path/to/file/mesh.stl')
168+
169+
Exporting AMF
170+
##############
171+
172+
The AMF exporter is capable of adjusting the quality of the resulting mesh, and accepts the following parameters.
173+
174+
* ``fileName`` - The path and file name to write the AMF output to.
175+
* ``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.
176+
* ``angularTolerance`` - Angular deflection setting which limits the angle between subsequent segments in a polyline. Default is 0.1.
177+
178+
For more complex objects, some experimentation with ``tolerance`` and ``angularTolerance`` may be required to find the
179+
optimum values that will produce an acceptable mesh. Note that parameters for AMF color and material are absent.
180+
181+
.. code-block:: python
182+
183+
import cadquery as cq
184+
from cadquery import exporters
185+
186+
result = cq.Workplane().box(10, 10, 10)
187+
188+
exporters.export(result, '/path/to/file/mesh.amf', tolerance=0.01, angularTolerance=0.1)
189+
190+
191+
Exporting TJS
192+
##############
193+
194+
The TJS (ThreeJS) exporter is capable of adjusting the quality of the resulting JSON-based mesh, and accepts the following parameters.
195+
196+
* ``fileName`` - The path and file name to write the ThreeJS output to.
197+
* ``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.
198+
* ``angularTolerance`` - Angular deflection setting which limits the angle between subsequent segments in a polyline. Default is 0.1.
199+
200+
For more complex objects, some experimentation with ``tolerance`` and ``angularTolerance`` may be required to find the
201+
optimum values that will produce an acceptable mesh.
202+
203+
.. code-block:: python
204+
205+
import cadquery as cq
206+
from cadquery import exporters
207+
208+
result = cq.Workplane().box(10, 10, 10)
209+
210+
exporters.export(result, '/path/to/file/mesh.json', tolerance=0.01, angularTolerance=0.1, exportType=exporters.ExportTypes.TJS)
211+
212+
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``
213+
had been used, CadQuery would have understood to use the ``TJS`` export format.
214+
215+
Exporting VRML
216+
###############
217+
218+
The VRML exporter is capable of adjusting the quality of the resulting mesh, and accepts the following parameters.
219+
220+
* ``fileName`` - The path and file name to write the VRML output to.
221+
* ``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.
222+
* ``angularTolerance`` - Angular deflection setting which limits the angle between subsequent segments in a polyline. Default is 0.1.
223+
224+
For more complex objects, some experimentation with ``tolerance`` and ``angularTolerance`` may be required to find the
225+
optimum values that will produce an acceptable mesh.
226+
227+
.. code-block:: python
228+
229+
import cadquery as cq
230+
from cadquery import exporters
231+
232+
result = cq.Workplane().box(10, 10, 10)
233+
234+
exporters.export(result, '/path/to/file/mesh.vrml', tolerance=0.01, angularTolerance=0.1)
156235
157236
Exporting Other Formats
158237
########################
238+
239+
The remaining export formats do not accept any additional parameters other than file name, and can be exported
240+
using the following structure.
241+
242+
.. code-block:: python
243+
244+
import cadquery as cq
245+
from cadquery import exporters
246+
247+
result = cq.Workplane().box(10, 10, 10)
248+
249+
exporters.export(result, '/path/to/file/object.[file_extension]')
250+
251+
Be sure to use the correct file extension so that CadQuery can determine the export format. If in doubt, fall
252+
back to setting the type explicitly by using :py:class:`exporters.ExportTypes`.
253+
254+
For example:
255+
256+
.. code-block:: python
257+
258+
import cadquery as cq
259+
from cadquery import exporters
260+
261+
result = cq.Workplane().box(10, 10, 10)
262+
263+
exporters.export(result, '/path/to/file/object.dxf', exporters.ExportTypes.DXF)

0 commit comments

Comments
 (0)