0
$\begingroup$

I'm a 3d artist trying to understand Python for Blender and develop a buttons plugin for the n-menu. I'm trying to understand a line in the code below, I adapted it so it shows only the interesting parts.

    import bpy

class BakeTool_Settings(bpy.types.PropertyGroup):


    profile_type_enum =[        ("EASY","Easy","",1),
                                ("EXPERT","Expert","",2)]

    profile_type : bpy.props.EnumProperty(name="PassMode",default = "EASY", items = profile_type_enum,description="Select the Pass Bake Mode")

class BakeTool_JobSettings(bpy.types.PropertyGroup):
    name : bpy.props.StringProperty()
    enabled : bpy.props.BoolProperty(default = True)    
    job_settings : bpy.props.PointerProperty(type=BakeTool_Settings)

class BakeTool_Jobs(bpy.types.PropertyGroup):
    Jobs : bpy.props.CollectionProperty(type=BakeTool_JobSettings)    
    index : bpy.props.IntProperty()
    
Job = bpy.context.scene.BakeTool_Jobs    
    
ActiveJob = Job.Jobs[Job.index]

def register():
    
    bpy.utils.register_class(BakeTool_Settings)
    bpy.utils.register_class(BakeTool_JobSettings)
    bpy.utils.register_class(BakeTool_Jobs)

    

def unregister():
    bpy.utils.unregister_class(BakeTool_Settings)
    bpy.utils.unregister_class(BakeTool_JobSettings)
    bpy.utils.unregister_class(BakeTool_Jobs)


if __name__ == "__main__":
    register()

It's further on used to draw a panel row:

layout.prop(ActiveJob.job_settings,"profile_type", text="Setup Mode",toggle = True, icon = "LIGHT",expand=True)

The thing I wanted to know is what is the 'ActiveJob = Job.Jobs[Job.index]' poiting to? In my perception the bracketed content is a synonym of 'bpy.props.IntProperty()' but I don't understand what is it doing. Thanks!

$\endgroup$
3
  • $\begingroup$ a collection property is a list, and [] is the python syntax to access a specific item of a list by its index. I can only recommend you follow a few crash courses in python where you will learn all of that :) $\endgroup$
    – Gorgious
    Commented Jun 5, 2023 at 19:45
  • $\begingroup$ Oh I see! I've done some beginer courses already, but I stumble on semantics every now and then. But in this case, I'm a little more confused because it points to a list index, but what exactly is pointing that index? An IntProperty? What is defining that IntProperty? $\endgroup$
    – AAA Yerus
    Commented Jun 6, 2023 at 7:07
  • 1
    $\begingroup$ I think this is just a convenience property to achieve the notion of "active" job. The index points to the job that is considered active in whatever context of the addon. It is used for example in the UI List feature $\endgroup$
    – Gorgious
    Commented Jun 6, 2023 at 9:34

0

You must log in to answer this question.

Browse other questions tagged .