0

I've created an Addon which create a standard Light Rig with parameters for adjusting light intensity and color. After executing the code, the parameter of color shows in the addon while the one which associated to intensity doesn't display. Before creating the script, I used the python console to help me to create the addon. The code to access/get the color of the light (bpy.context.object.data.color)and that of (bpy.context.object.data.energy) appear to be similar. So I created the script below to try to create the attributes to change light intensity and color. But it seems it only works for color but not for intensity. I have looked up the documentation and have been thinking about using PointerProperty to get the intensity by bpy.types.AreaLight from bpy.types.Light and bpy.types.Object. But it doesn't work and it's not displayed in my Addon.

  import bpy from bpy.props import FloatProperty, FloatVectorProperty

class LightSetPanel(bpy.types.Panel):

bl_label = "Lighting Rig Add-On"
bl_idname = "LIGHT_PT_PANEL"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Light Rig"

def draw(self, context):
    layout = self.layout
    row = layout.row()
    row.operator("light.rig_operator")
    ob = bpy.context.active_object
    da = ob.data
    row=layout.row()
    row.prop(da,"color")
    row= layout.row()
    row.prop(da, "intensity")


def updateIntensity(self,context): obj = bpy.context.active_object light = obj.data light.energy = self.intensity light.color = self.color

class LightParamSet(bpy.types.PropertyGroup):

intensity: FloatProperty(
    name="intensity",
    subtype="POWER",
    min=0, max= 12,
    update = updateIntensity)

color : FloatVectorProperty(
    name="color",
    subtype="COLOR",
    update = updateIntensity)

def register(): bpy.utils.register_class(LightSetPanel) bpy.utils.register_class(LIGHT_RIG) bpy.utils.register_class(LightParamSet)

def unregister(): bpy.utils.unregister_class(LightSetPanel) bpy.utils.unregister_class(LIGHT_RIG) bpy.utils.unregister_class(LightParamSet)

if name == "main": register()

The screenshot of the Addon after executing the Python script.

enter image description here

A big thanks if anyone can help.

Kayla Man
  • 61
  • 3
  • 2
    It doesn't work because your property group is not registered to the scene properly. In your register function add eg. bpy.types.Scene.my_tool = PointerProperty(type=LightParamSet), this way you can access your properties per scene reference: context.scene.my_tool.intensity, and thus row.prop(context.scene.my_tool, "intensity") in the layout, read: How to create a custom UI? – brockmann Apr 16 '21 at 10:23
  • Many thanks for that. It works now =) – Kayla Man Apr 17 '21 at 11:52
  • was commenting on recently deleted and it well disappeared. A similar question, re pics in UI, came up 14 or so years ago on BA. IIRC one of the devs mentioned this was deliberately so to avoid clutter. Prob the chioce is use an icon in header, and even though it's only an Icon it does leap out of a sparse interface. – batFINGER Sep 13 '21 at 15:06
  • I see. The reason why I delete the question is I feel that I probably won't include the icon as a header even if I find out the answer. The sample script is a bit long for loading the image without any executable function. Besides, (it's very personal)I think it's strange to use Python to call GL Function in blender to bind texture, as suggested by the sample scripts in the suggested answer within the forum. – Kayla Man Sep 13 '21 at 15:23

0 Answers0