Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DXF Codec #25

Merged
merged 2 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/cq_cli/cqcodecs/cq_codec_dxf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os, tempfile
from cadquery import exporters
import cq_cli.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_dxf.dxf")

# The exporters will add extra output that we do not want, so suppress it
with helpers.suppress_stdout_stderr():
# Put the DXF output into the temp file
exporters.export(
build_result.results[0].shape,
temp_file,
exporters.ExportTypes.DXF,
opt=output_opts,
)

# Read the DXF output back in
with open(temp_file, "r") as file:
dxf_str = file.read()

return dxf_str
2 changes: 0 additions & 2 deletions src/cq_cli/cqcodecs/cq_codec_gltf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os, tempfile
from cadquery import exporters
import cadquery as cq
import cq_cli.cqcodecs.codec_helpers as helpers


Expand Down
1 change: 0 additions & 1 deletion src/cq_cli/cqcodecs/cq_codec_svg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os, tempfile
from cadquery import exporters
import cadquery as cq
import cq_cli.cqcodecs.codec_helpers as helpers


Expand Down
20 changes: 20 additions & 0 deletions tests/test_dxf_codec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import tests.test_helpers as helpers


def test_dxf_codec():
"""
Basic test of the DXF codec plugin.
"""
test_file = helpers.get_test_file_location("cube.py")

command = [
"python",
"src/cq_cli/main.py",
"--codec",
"dxf",
"--infile",
test_file,
]
out, err, exitcode = helpers.cli_call(command)

assert out.decode().split("\n")[1].replace("\r", "") == "SECTION"
Loading