CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
2.94k stars 276 forks source link

AMF exporter issue? #616

Open ebak opened 3 years ago

ebak commented 3 years ago

Snippet:

import cadquery as cq
from cadquery import Vector
from cadquery import exporters

wp = cq.Workplane('front')

if True:
    # --- simple union example ---
    sp1 = wp.sphere(radius=10).translate(Vector(-5, 0, 0))
    sp2 = wp.sphere(radius=8).translate(Vector(5, 0, 0))

    scene = sp1.union(toUnion=sp2)

    with open('try.amf', 'w') as f:
        f.write(exporters.toString(sp1, 'AMF', 0.01))

Problem (line numbers are not in sync with the snippet lines):

Traceback (most recent call last):
  File "/home/bobajfej/Prg/CQModels/try.py", line 19, in <module>
    f.write(exporters.toString(sp1, 'AMF', 0.01))
  File "/home/bobajfej/Prg/CQModels/env.conda/lib/python3.8/site-packages/cadquery/utils.py", line 36, in wrapped
    return f(*args, **kwargs)
  File "/home/bobajfej/Prg/CQModels/env.conda/lib/python3.8/site-packages/cadquery/occ_impl/exporters/__init__.py", line 115, in toString
    exportShape(shape, exportType, s, tolerance, angularTolerance)
  File "/home/bobajfej/Prg/CQModels/env.conda/lib/python3.8/site-packages/cadquery/utils.py", line 36, in wrapped
    return f(*args, **kwargs)
  File "/home/bobajfej/Prg/CQModels/env.conda/lib/python3.8/site-packages/cadquery/occ_impl/exporters/__init__.py", line 167, in exportShape
    aw.writeAmf(fileLike)
  File "/home/bobajfej/Prg/CQModels/env.conda/lib/python3.8/site-packages/cadquery/occ_impl/exporters/amf.py", line 39, in writeAmf
    amf = ET.ElementTree(amf).write(outFile, xml_declaration=True)
  File "/home/bobajfej/Prg/CQModels/env.conda/lib/python3.8/xml/etree/ElementTree.py", line 772, in write
    serialize(write, self._root, qnames, namespaces,
  File "/home/bobajfej/Prg/CQModels/env.conda/lib/python3.8/xml/etree/ElementTree.py", line 937, in _serialize_xml
    _serialize_xml(write, e, qnames, None,
  File "/home/bobajfej/Prg/CQModels/env.conda/lib/python3.8/xml/etree/ElementTree.py", line 937, in _serialize_xml
    _serialize_xml(write, e, qnames, None,
  File "/home/bobajfej/Prg/CQModels/env.conda/lib/python3.8/xml/etree/ElementTree.py", line 937, in _serialize_xml
    _serialize_xml(write, e, qnames, None,
  [Previous line repeated 2 more times]
  File "/home/bobajfej/Prg/CQModels/env.conda/lib/python3.8/xml/etree/ElementTree.py", line 912, in _serialize_xml
    write("<" + tag)
TypeError: string argument expected, got 'bytes'

Version: cadquery 2.1RC1 py3.8 cadquery

adam-urbanczyk commented 3 years ago

toString is deprecated (and maybe even not working by now). Use the following:

exporters.export(scene,'try.amf')