Skip to content

Commit 2b2c06b

Browse files
committed
Started to add dedicated import-export doc
1 parent dc15aea commit 2b2c06b

File tree

4 files changed

+200
-0
lines changed

4 files changed

+200
-0
lines changed
Lines changed: 33 additions & 0 deletions
Loading
Lines changed: 46 additions & 0 deletions
Loading

doc/importexport.rst

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
.. _importexport:
2+
3+
******************************
4+
Importing and Exporting Files
5+
******************************
6+
7+
Introduction
8+
============
9+
10+
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
12+
does not support any formats that carry parametric data with them at this time. The only format that is fully
13+
parametric is CadQuery's own Python format. Below are lists of the import and export file formats that CadQuery
14+
supports.
15+
16+
Import Formats
17+
###############
18+
19+
* DXF
20+
* STEP
21+
22+
Export Formats
23+
###############
24+
25+
* DXF
26+
* SVG
27+
* STEP
28+
* STL
29+
* AMF
30+
* TJS
31+
* VRML
32+
33+
Notes on the Formats
34+
#######################
35+
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.
41+
42+
Importing DXF
43+
##############
44+
45+
Importing STEP
46+
###############
47+
48+
Exporting SVG
49+
##############
50+
51+
The SVG exporter has several options which can be useful for getting the desired final output. Those
52+
options are as follows.
53+
54+
* *width* - Document width of the resulting image.
55+
* *height* - Document height of the resulting image.
56+
* *marginLeft* - Inset margin from the left side of the document.
57+
* *marginTop* - Inset margin from the top side of the document.
58+
* *projectionDir* - Direction the camera will view the shape from.
59+
* *showAxes* - Whether or not to show the axes indicator, which will only be visible when the projectionDir is also at the default.
60+
* *strokeWidth* - Width of the line that visible edges are drawn with.
61+
* *strokeColor* - Color of the line that visible edges are drawn with.
62+
* *hiddenColor* - Color of the line that hidden edges are drawn with.
63+
* *showHidden* - Whether or not to show hidden lines.
64+
65+
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.
66+
Below are a few examples.
67+
68+
Without options:
69+
70+
.. code-block:: python
71+
72+
import cadquery as cq
73+
from cadquery import exporters
74+
75+
result = cq.Workplane().box(10, 10, 10)
76+
77+
exporters.export(result, '/path/to/file/box.svg')
78+
79+
Results in:
80+
81+
.. image:: _static/importexport/box_default_options.svg
82+
83+
Note that the exporters API figured out the format type from the file extension. The format
84+
type can be set explicitly by using :py:class:`exporters.ExportTypes`.
85+
86+
The following is an example of using options to alter the resulting SVG output by passing in the opt parameter.
87+
88+
.. code-block:: python
89+
90+
import cadquery as cq
91+
from cadquery import exporters
92+
93+
result = cq.Workplane().box(10, 10, 10)
94+
95+
exporters.export(
96+
result,
97+
'/path/to/file/box_custom_options.svg',
98+
opt={
99+
"width": 300,
100+
"height": 300,
101+
"marginLeft": 10,
102+
"marginTop": 10,
103+
"showAxes": False,
104+
"projectionDir": (0.5, 0.5, 0.5),
105+
"strokeWidth": 0.25,
106+
"strokeColor": (255, 0, 0),
107+
"hiddenColor": (0, 0, 255),
108+
"showHidden": True,
109+
},
110+
)
111+
112+
Which results in the following image:
113+
114+
.. image:: _static/importexport/box_custom_options.svg
115+
116+
Exporting STL
117+
##############
118+
119+
Exporting Other Formats
120+
########################

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Table Of Contents
4444
apireference.rst
4545
selectors.rst
4646
classreference.rst
47+
importexport.rst
4748
cqgi.rst
4849
extending.rst
4950
roadmap.rst

0 commit comments

Comments
 (0)