-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from CadQuery/svg
Adding the SVG Codec and Support for Codec Options
- Loading branch information
Showing
6 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os, tempfile | ||
from cadquery import exporters | ||
import cadquery as cq | ||
import cqcodecs.codec_helpers as helpers | ||
|
||
def convert(build_result, output_file=None, error_file=None, output_opts=None): | ||
# Create a temporary file to put the STL output into | ||
temp_dir = tempfile.gettempdir() | ||
temp_file = os.path.join(temp_dir, "temp_svg.svg") | ||
|
||
# The exporters will add extra output that we do not want, so suppress it | ||
with helpers.suppress_stdout_stderr(): | ||
# Put the STEP output into the temp file | ||
exporters.export(build_result.results[0].shape, temp_file, exporters.ExportTypes.SVG, opt=output_opts) | ||
|
||
# Read the STEP output back in | ||
with open(temp_file, 'r') as file: | ||
step_str = file.read() | ||
|
||
return step_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import tests.test_helpers as helpers | ||
|
||
def test_svg_codec(): | ||
""" | ||
Basic test of the SVG codec plugin. | ||
""" | ||
test_file = helpers.get_test_file_location("cube.py") | ||
|
||
command = ["python", "cq-cli.py", "--codec", "svg", "--infile", test_file, "--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;"] | ||
out, err, exitcode = helpers.cli_call(command) | ||
|
||
assert out.decode().split('\n')[0].replace('\r', '') == "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" |