Skip to content

Commit a71a93e

Browse files
authored
Update cqgi.rst with a helpful example (#711)
* Update cqgi.rst
1 parent 39e60f6 commit a71a93e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

doc/cqgi.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,32 @@ See the CQGI API docs for more details.
141141

142142
Future enhancements will include a safer sandbox to prevent malicious scripts.
143143

144+
Automating export to STL
145+
-------------------------
146+
A common use-case for the CQGI is the automation of processing cadquery code into geometry, doing so via the CQGI rather than an export line in the script itself leads to a much tidier environment; you may need to do this as part of an automated-workflow, batch-conversion, exporting to another software for assembly, or running stress simulations on resulting bodies.
147+
148+
The below Python script demonstrates how to open, process, and export an STL file from any valid cadquery script::
149+
150+
# Load CQGI
151+
import cadquery.cqgi as cqgi
152+
import cadquery as cq
153+
154+
# load the cadquery script
155+
model = cqgi.parse(open("example.py").read())
156+
157+
# run the script and store the result (from the show_object call in the script)
158+
build_result = model.build()
159+
160+
# test to ensure the process worked.
161+
if build_result.success:
162+
# loop through all the shapes returned and export to STL
163+
for i, result in enumerate(build_result.results):
164+
cq.exporters.export(result.shape, f"example_output{i}.stl")
165+
else:
166+
print(f"BUILD FAILED: {build_result.exception}")
167+
168+
169+
144170
Important CQGI Methods
145171
-------------------------
146172

0 commit comments

Comments
 (0)