Skip to content

Constructing an Assembly object directly with a Workplane object and then calling toCAF produces an exception #1922

@jmwright

Description

@jmwright

To Reproduce

The following code produces an exception (backtrace with exception pasted below).

from cadquery.occ_impl.assembly import toCAF
import cadquery as cq

result1 = cq.Workplane("XY" ).box(3, 3, 0.5)

assy = cq.Assembly(result1)

label, shape = toCAF(assy)

Whereas the following code does NOT produce the exception:

from cadquery.occ_impl.assembly import toCAF
import cadquery as cq

result1 = cq.Workplane("XY" ).box(3, 3, 0.5)

assy = cq.Assembly()
assy.add(result1)

label, shape = toCAF(assy)

Backtrace

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/repos/cadquery/cadquery/occ_impl/assembly.py", line 432, in toCAF
    top = _toCAF(assy, None)
          ^^^^^^^^^^^^^^^^^^
  File "/home/user/repos/cadquery/cadquery/occ_impl/assembly.py", line 426, in _toCAF
    tool.SetLocation(subassy, assy.loc.wrapped, rv)
                     ^^^^^^^
UnboundLocalError: cannot access local variable 'subassy' where it is not associated with a value

Environment

OS: Appveyor CI for CQ-editor, both Ubuntu 22.04 and Windows Server 2019. Also created the MRE locally on Debian 12, CQ installed via pip, with same result.

Installing via conda or pip produces the same error. It seems to be tied to the CadQuery 2.6.0 release as this is not an issue with a CadQuery 2.5.2 environment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    assemblybugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions