Skip to content

Commit 1f2f16e

Browse files
committed
Added linear and agular deflection settings to STL codec
1 parent 2d04530 commit 1f2f16e

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ cat /input/path/script.py | cq-cli.py --codec step | wc -l
8282
```
8383
./cq-cli.py --codec svg --infile /input/path/script.py --outfile /output/path/newfile.svg --outputopts "width:100;height:100;marginLeft:12;marginTop:12;showAxes:False;projectionDir:(0.5,0.5,0.5);strokeWidth:0.25;strokeColor:(255,0,0);hiddenColor:(0,0,255);showHidden:True;"
8484
```
85+
8. Convert a CadQuery script to STL, passing in output options to change the quality of the resulting STL. Explanation of linear vs angular deflection can be found [here](https://dev.opencascade.org/doc/occt-7.1.0/overview/html/occt_user_guides__modeling_algos.html#occt_modalg_11_2).
86+
```
87+
./cq-cli.py --codec stl --infile /input/path/script.py --outfile /input/path/script.stl --outputopts "linearDeflection:0.3;angularDeflection:0.3"
88+
```
8589

8690
## Drawbacks
8791

cqcodecs/cq_codec_stl.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@ def convert(build_result, output_file=None, error_file=None, output_opts=None):
88
temp_dir = tempfile.gettempdir()
99
temp_file = os.path.join(temp_dir, "temp_stl.stl")
1010

11+
linearDeflection = 0.1
12+
angularDeflection = 0.1
13+
14+
# If the user has provided the deflection settings, use them
15+
if "linearDeflection" in output_opts:
16+
linearDeflection = output_opts["linearDeflection"]
17+
if "angularDeflection" in output_opts:
18+
angularDeflection = output_opts["angularDeflection"]
19+
1120
# The exporters will add extra output that we do not want, so suppress it
1221
with helpers.suppress_stdout_stderr():
1322
# Put the STEP output into the temp file
14-
exporters.export(build_result.results[0].shape, temp_file, exporters.ExportTypes.STL)
23+
exporters.export(build_result.results[0].shape, temp_file, exporters.ExportTypes.STL, tolerance=linearDeflection, angularTolerance=angularDeflection)
1524

1625
# Read the STEP output back in
1726
with open(temp_file, 'r') as file:

0 commit comments

Comments
 (0)