Hello all,
I just started with Cadquery and tried to create my first model. I got at a point where I needed to use the some more complex geometry several times. I think this is a common thing you are facing during the creation of a 3D model. And I think it is also useful if you want to reuse the same geometry (let's say a holder) which somehow standard in several models.
As far as I have understood, assemblies should be used for this, correct?
I tried this, but it only worked partly. My main problem is currently to setup the constrains of the final assembly. I found that in the examples often tags are used, so I started with that. But I found that I cannot reference the tags from a subassembly. I made a short simple example which hopefully says more than thousand words:
import cadquery as cq
#### first part as subassembly ###
subpart1 = cq.Workplane("XY").box(10,10,10)
subpart1.faces(">Z").tag("top")
subpart2 = cq.Workplane("XY").box(3,3,3)
subassembly = (cq.Assembly()
.add(subpart1, name="subpartX1")
.add(subpart2, name="subpartX2")
.constrain("subpartX1@faces@>X", "subpartX2@faces@>X", "Plane")
)
subassembly.solve()
#show_object(subassembly)
### second part ###
part2 = cq.Workplane("XY").box(5,15,5)
part2.faces(">Y").tag("left")
part2.faces(">X").tag("right")
### the assemblies ###
#adding the subassembly as compound works, but I cannot reference the tag from the subassembly
assy1 = (
cq.Assembly()
.add(subassembly.toCompound(), name="partX", color=cq.Color("orange"))
.add(part2, name="part2", color=cq.Color("red"))
#this works
.constrain("partX@faces@>X", "part2?right", "Plane")
#this does not work
#.constrain("partX?top", "part2?right", "Plane")
)
assy1.solve()
show_object(assy1)
#adding the subassembly as assembly works, but the constrain is not working
assy2 = (
cq.Assembly()
.add(subassembly, name="partX", color=cq.Color("orange"))
.add(part2, name="part2", color=cq.Color("red"))
#this does not work
#.constrain("partX@faces@>X", "part2?right", "Plane")
)
#assy2.solve()
#show_object(assy2)