import bpy class MESH_OT_led_strip(bpy.types.Operator): """Add a LED strip""" bl_idname = 'mesh.led_strip' bl_label = 'Add LED Strip' bl_options = { 'REGISTER', 'UNDO' } led_num: bpy.props.IntProperty( name = 'Addressable Leds', description = 'Number of addresabble leds in the Strip', default = 60, min = 1, soft_max = 300, ) led_model: bpy.props.EnumProperty( name = 'Model', description = 'Led model (ej. WS2812)', items = [ ('WS2812', 'WS2812', 'Individually addressable'), ('WS2811', 'WS2811', 'Addressable every 3'), ], default = 'WS2812' ) led_density: bpy.props.EnumProperty( name = 'Density', description = 'Leds per meter', items = [ ('30', '30', '30 leds per meter'), ('60', '60', '60 leds per meter'), ('144', '144', '144 leds per meter'), ], default = '60' ) @classmethod def poll(cls, context): return context.area.type == 'VIEW_3D' def execute(self, context): separation = 0.05 x_size = (100 - (separation * int(self.led_density))) / int(self.led_density) print(x_size) if self.led_model == 'WS2811': x_scale = 3 else: x_scale = 1 last_object = None for i in range(self.led_num): x_loc = ((x_size + separation) * x_scale ) * i bpy.ops.mesh.primitive_plane_add(size=1, location=(x_loc, 0, 0)) context.active_object.scale.x = x_scale * x_size # 3 leds for WS2811 bpy.ops.object.transform_apply() if last_object is not None: last_object.select_set(True) bpy.ops.object.join() last_object = bpy.context.active_object context.active_object.name = 'Led Strip ' + \ self.led_model + ' ' + \ self.led_density + '/m' context.active_object.color = [0.1, 0.1, 0.1, 1.0] bpy.ops.object.transform_apply() return {'FINISHED'} class VIEW3D_PT_lidrop(bpy.types.Panel): bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = 'LiDrop' bl_label = 'LiDrop' def draw(self, context): self.layout.operator('mesh.led_strip', text = 'Add a new LED Strip', icon = 'ONIONSKIN_ON') # TODO agregar una propiedad que me diga si el objeto activo es una led strip if context.active_object is not None \ and context.active_object.select_get(): nombre = context.active_object.name self.layout.label(text = nombre, icon = 'OBJECT_DATA') else: self.layout.label(text = 'No LED strip selected') # col = self.layout.column(align = True, heading = 'Light Drops') # obj = context.active_object # if obj is not None: # col.prop(context.active_object, 'color') # cuando no tienes nada seleccionado no debería desaparecer # col.prop(context.space_data.shading, 'color_type') def register(): print('Lidrop ON') bpy.utils.register_class(VIEW3D_PT_lidrop) bpy.utils.register_class(MESH_OT_led_strip) def unregister(): print('Lidrop OFF') bpy.utils.unregister_class(VIEW3D_PT_lidrop) bpy.utils.unregister_class(MESH_OT_led_strip)