You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When adding to an Assembly, it seems that the color/object tuples aren't correctly de-duplicating:
# define the current color
current_color = el.color if el.color else color
# add a leaf with the actual part if needed
if el.obj:
# get/register unique parts referenced in the assy
key0 = (current_color, el.obj) # (color, shape) # <<------- a different object (not value) here
key1 = el.obj # shape
if key0 in unique_objs: # <---- fails this check
lab = unique_objs[key0]
else:
lab = tool.NewShape()
if key1 in compounds:
If you add items to the assembly using a single Color, it's works like you expect:
def single_color_object():
# Create an assembly
assembly = cq.Assembly()
color = cq.Color(0, 0, 1) # <---- same!
# Add 4 cubes in a 2x2 grid
for i in range(2):
for j in range(2):
assembly.add(
cube,
loc=cq.Location(
cq.Vector(i * 2, j * 2, 0),
),
# Same object each time
color=color,
)
return assembly
This returns 4 cubes all the same object (exports to ~25kB)
If you make a new color each time with the same value, you get duplicated cubes:
def multi_same_color_object():
# Create an assembly
assembly = cq.Assembly()
# Add 4 cubes in a 2x2 grid
for i in range(2):
for j in range(2):
assembly.add(
cube,
loc=cq.Location(
cq.Vector(i * 2, j * 2, 0),
),
# This is always the same value, but it's a different object
color=cq.Color(0, 0, 1),
)
return assembly
This returns 4 same coloured cubes, but they're all "new" objects (exports to ~75kB)
In fact, you can even subvert it the other way by changing the value, not the object:
def multi_different_color_object():
# Create an assembly
assembly = cq.Assembly()
color = cq.Color(0, 0, 1)
# Add 4 cubes in a 2x2 grid
for i in range(2):
for j in range(2):
# Change the color "secretly"
color.r = i / 2
color.g = j / 2
color.b = 0
assembly.add(
cube,
loc=cq.Location(
cq.Vector(i * 2, j * 2, 0),
),
# Same object each time
# but the value changed
color=color,
)
return assembly
Saving this makes 4 identically coloured cubes (exports to ~25kB)
It seems to me that this should be a by-value comparison rather than checking if it's literally the same object?
When
add
ing to anAssembly
, it seems that the color/object tuples aren't correctly de-duplicating:If you add items to the assembly using a single
Color
, it's works like you expect:This returns 4 cubes all the same object (exports to ~25kB)
If you make a new color each time with the same value, you get duplicated cubes:
This returns 4 same coloured cubes, but they're all "new" objects (exports to ~75kB)
In fact, you can even subvert it the other way by changing the value, not the object:
Saving this makes 4 identically coloured cubes (exports to ~25kB)
It seems to me that this should be a by-value comparison rather than checking if it's literally the same object?
Script to replicate:
cq_export_color.zip
Version:
The text was updated successfully, but these errors were encountered: