I understand that with the newest API change, scripts cannot access some stuff… a lot of stuff, during their loading. Like, they can’t modify scene’s props. Which is why I’m writing this. See, I got an export script for a custom model format that I’ve made and you could add “tags” to model parts (like, if the model had a gun turret, you’d add a tag to let the game engine know it can rotate that part when aiming at an enemy, for example). It’s very flexible, you can chose from preset tags or you could add a custom tag, set its ID and value and it’d get exported in the file.
I used a PropertyGroup called TagProperties (it actually had just one property, type) and a CollectionProperty based on it. For preset tags, I had a dictionary, like this:
# key = tag name
# value[0] = tag's export value
# value[1] = tag's type, we check this when drawing the panel
# value[2] = desription, it's also used for panel
VALID_TAGS = {
'ROT_AXIS': (150, 'str', 'Single character, X, Y or Z'),
'ROT_LIMIT_PLUS': (151, 'int', 'Rotation limit in degrees (positive)'),
'ROT_LIMIT_MINUS': (152, 'int', 'Rotation limit in degrees (negative)'),
'OBJECT_GROUP': (160, 'int', 'Sets a relation beetween different objects through a common ID number'),
'LOC_SLIDE_AXIS': (170, 'str', 'Slide axis'),
'AIM_ROT_YAW_AXIS': (180, 'str', 'Aim axis (yaw)'),
'AIM_ROT_YAW_FACTOR': (181, 'float', 'Aim axis factor (yaw)'),
'AIM_ROT_PITCH_AXIS': (182, 'float', 'Aim axis (pitch)'),
'AIM_ROT_PITCH_FACTOR': (183, 'int', 'Aim axis factor (pitch)'),
'AUTO_ANIM_TYPE': (120, 'str', 'rot, slide'),
'AUTO_ANIM_AXIS': (121, 'str', 'X, Y or Z'),
'AUTO_ANIM_MAX': (122, 'float', 'Max'),
'AUTO_ANIM_MIN': (123, 'float', 'Min')
}
and when the script executed, ran:
bpy.context.scene.valid_tags.clear()
for tag in VALID_TAGS:
new_tag = bpy.context.scene.valid_tags.add()
new_tag.name = tag
new_tag.type = VALID_TAGS[tag][0]
To first clear the valid_tags CollectionProperty of the current active scene and then populate it with preset tags. This is how it looked like when the addon loaded:
But now, my script cannot access the current scene through bpy.context.scene. I also tried to set valid_tags of all scenes, like this:
for s in bpy.data.scenes:
s.valid_tags.clear()
for tag in VALID_TAGS:
new_tag = s.valid_tags.add()
new_tag.name = tag
new_tag.type = VALID_TAGS[tag][0]
but no, still can’t do it. And I don’t understand why, when I open a .blend file and go to the user preferences dialog to turn on my addon, there should be no reason for it to not be able to access the scene’s properties and modify them. Why they restricted this seems simply mind bogglingly stupid to me.
I know I can load the script in text editor and Alt+P it from there and it’d get exectuted. Also, I know I can add an operator to a panel and populate the collection property from there but - I don’t want to do all that every time a new .blend file is loaded. Is there any way to do this on an event of sorts, like “on-file-loaded” -> run this? Or is there an other way of achieving this functionality?