@@ -29,6 +29,8 @@ def transform(self, native_mesh, transformation):
2929
3030 def draw_geometry (self , geometry , name = None , color = None ):
3131 # Imported colors take priority over a the parameter color
32+ # TODO: cleanup confusion between layers and collections
33+
3234 if 'mesh_color.diffuse' in geometry .attributes :
3335 color = geometry .attributes ['mesh_color.diffuse' ]
3436
@@ -40,11 +42,22 @@ def draw_geometry(self, geometry, name=None, color=None):
4042 color = [1. , 1. , 1. ]
4143
4244 if self .layer :
43- collection = bpy .data .collections .new (self .layer )
44- bpy .context .scene .collection .children .link (collection )
45+
46+ current_collections = bpy .data .collections .items ()
47+ #print(bpy.data.collections)
48+ #print(bpy.data.collections.keys())
49+
50+ if self .layer not in bpy .data .collections .keys ():
51+ collection = bpy .data .collections .new (self .layer ) # create new collection if none exists
52+ bpy .context .scene .collection .children .link (collection ) # link the new collection to the base collection
53+ else :
54+ collection = bpy .data .collections .get (self .layer )
55+ # print(collection)
56+
4557
4658 v , f = geometry .to_vertices_and_faces ()
47- return compas_blender .draw_mesh (vertices = v , faces = f , name = name , color = color , centroid = False , layer = self .layer )
59+ # Draw the mesh in blender in the specified collection
60+ return compas_blender .draw_mesh (vertices = v , faces = f , name = name , color = color , centroid = False , collection = self .layer )
4861
4962 def redraw (self , timeout = None ):
5063 bpy .ops .wm .redraw_timer (type = 'DRAW_WIN_SWAP' , iterations = 1 )
0 commit comments