CadQuery / cadquery

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

Assembly not as expected, duplicate items appear #1500

Closed GaN-T closed 10 months ago

GaN-T commented 10 months ago

I am trying to make a simple stack of boxes as an assembly. When I create the boxes and visualize them individually they appear to have the correct thickness and position. But when i add them to the assembly, it doesn't look right. I am seeing five boxes in the stack instead of three. What am I doing wrong? The expected output is 3 boxes stacked on top of each other with increasing thicknesses (10, 30, 50) when viewed from the side going down towards the XY plane.

box0 = cq.Workplane("front").box(50,50,50)
box1 = box0.faces(">Z").workplane().box(50,50,30, combine =False)
box2 = box1.faces(">Z").workplane().box(50,50,10, combine =False)
assy = cq.Assembly()
assy.add(box0, name =  "0").add(box1, name =  "1").add(box2, name =  "2")
GaN-T commented 10 months ago

Nevermind, I found my mistake: I had to center the new objects correctly. The code below gives the right output:

box0 = cq.Workplane("front").box(50,50,50)
box1 = box0.faces(">Z").workplane().box(50,50,30, centered = [1,1,0], combine =False)
box2 = box1.faces(">Z").workplane().box(50,50,10, centered = [1,1,0],  combine =False)
assy = cq.Assembly()
assy.add(box0, name =  "0").add(box1, name =  "1").add(box2, name =  "2")