Skip to content

Commit 09f84d7

Browse files
Rework the CQGI example
1 parent f459994 commit 09f84d7

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

doc/cqgi.rst

+5-13
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Automating export to STL
145145
-------------------------
146146
A common use-case for the CQGI is the automation of processing cad-query code into geometary, doing so via the CQGI rather than an export line in the script-itself lead to a much tidier enviroment; 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.
147147

148-
The below python script demonstrates how to open, process, and export and STL file from any valid cadquery script.
148+
The below python script demonstrates how to open, process, and export and STL file from any valid cadquery script::
149149

150150
# Load CQGI
151151
import cadquery.cqgi as cqgi
@@ -159,19 +159,11 @@ The below python script demonstrates how to open, process, and export and STL fi
159159
160160
# test to ensure the process worked.
161161
if build_result.success:
162-
count = 0;
163-
# loop through all the shapes returned
164-
for result in build_result.results:
165-
# open the output file (count variable is used here such that the output would be:
166-
# example_output0.stl, example_output1.stl, etc for each returned shape
167-
with open('example_output'+ str(count) + '.stl', 'w') as f:
168-
//write the result of exporting as an STL
169-
f.write(cq.exporters.toString(result.shape, 'STL', 10))
170-
f.close();
171-
//increment count for more shapes
172-
count = count + 1;
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")
173165
else:
174-
print( "BUILD FAILED: " + str(build_result.exception) + "\n");
166+
print(f"BUILD FAILED: {build_result.exception}")
175167

176168

177169

0 commit comments

Comments
 (0)