Skip to content

Commit

Permalink
Update cqgi.rst with a helpful example (#711)
Browse files Browse the repository at this point in the history
* Update cqgi.rst
  • Loading branch information
DarthPJB authored Apr 6, 2021
1 parent 39e60f6 commit a71a93e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions doc/cqgi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,32 @@ See the CQGI API docs for more details.

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

Automating export to STL
-------------------------
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.

The below Python script demonstrates how to open, process, and export an STL file from any valid cadquery script::

# Load CQGI
import cadquery.cqgi as cqgi
import cadquery as cq
# load the cadquery script
model = cqgi.parse(open("example.py").read())
# run the script and store the result (from the show_object call in the script)
build_result = model.build()
# test to ensure the process worked.
if build_result.success:
# loop through all the shapes returned and export to STL
for i, result in enumerate(build_result.results):
cq.exporters.export(result.shape, f"example_output{i}.stl")
else:
print(f"BUILD FAILED: {build_result.exception}")



Important CQGI Methods
-------------------------

Expand Down

0 comments on commit a71a93e

Please sign in to comment.