Generating svg plots from cadquery assemblies
Last updated: Dec 18, 2023
How to generate svg plots from cadquery assemblies
The problem
The stable install of cq-editor (v0.2 at the time of writing) will not generate svg plots from assemblies. The error is:
AttributeError: ‘Assembly’ object has no attribute ‘wrapped’
But, but, but, we can make step files.
So, we read up a little and see that assemblies need to be made into a single renderable object to be rendered as a svg gile. We use the ’toCompound’ method on the assembly to amalgamate the assemble into a single renderable object and get the annoying message:
AttributeError: ‘Assembly’ object has not attribute ’toCompound’
Why?
Solution
The stable version of cq-editor (v0.2 when I wrote this blog) was made before the ’toCompound’ method was added to cadquery.
Install the unstable version of cq-editor from:
https://github.com/CadQuery/CQ-editor/releases/tag/nightly
The download is about 600Mb at the time of writing. Takes a while to install. The new install will generate svg files from assemlies using e.g.
import cadquery as cq
assy = cq.Assembly()
box1 = cq.Workplane().box(10, 10, 10)
box2 = cq.Workplane().center(10, 10).box(10, 10, 10)
assy.add(box1)
assy.add(box2)
show_object(assy)
assy = cq.Compound.makeCompound(assy)
cq.exporters.export(assy.toCompound(), 'assy.svg')
Note that you need to use the ’toCompound()’ method when using assemblies.
To get a particular projection, have a look at the documentation at:
https://cadquery.readthedocs.io/en/latest/importexport.html
Hours of fun!