-
Notifications
You must be signed in to change notification settings - Fork 10
/
bp_props.py
76 lines (63 loc) · 2.46 KB
/
bp_props.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import bpy
from bpy.types import (
Operator,
Panel,
PropertyGroup,
UIList,
)
from bpy.props import (
BoolProperty,
FloatProperty,
IntProperty,
PointerProperty,
StringProperty,
CollectionProperty,
EnumProperty,
)
import os
def update_object_selection(self,context):
if self.selected_object_index < len(context.scene.objects):
bpy.ops.object.select_all(action = 'DESELECT')
obj = context.scene.objects[self.selected_object_index]
obj.select_set(True)
context.view_layer.objects.active = obj
def update_object_selection_from_collection(self,context):
if self.selected_object_index < len(context.view_layer.active_layer_collection.collection.objects):
bpy.ops.object.select_all(action = 'DESELECT')
obj = context.view_layer.active_layer_collection.collection.objects[self.selected_object_index]
obj.select_set(True)
context.view_layer.objects.active = obj
def update_world_selection(self,context):
if self.selected_world_index <= len(bpy.data.worlds) - 1:
world = bpy.data.worlds[self.selected_world_index]
context.scene.world = world
class BP_Scene_Props(PropertyGroup):
selected_object_index: IntProperty(name="Selected Object Index", default=0, update = update_object_selection)
selected_world_index: IntProperty(name="Selected World Index", default=0, update = update_world_selection)
selected_material_index: IntProperty(name="Selected Material Index", default=0)
@classmethod
def register(cls):
bpy.types.Scene.bp_props = PointerProperty(
name="BP Props",
description="ProSidebar Props",
type=cls,
)
@classmethod
def unregister(cls):
del bpy.types.Scene.bp_props
class BP_Collection_Props(PropertyGroup):
is_expanded: BoolProperty(name="Is Expanded", default=False)
selected_object_index: IntProperty(name="Select Object Index", default=False,update = update_object_selection_from_collection)
@classmethod
def register(cls):
bpy.types.Collection.bp_props = PointerProperty(name="BP Props",description="Blender Pro Props",type=cls)
@classmethod
def unregister(cls):
del bpy.types.Collection.bp_props
classes = (
BP_Scene_Props,
BP_Collection_Props,
)
register, unregister = bpy.utils.register_classes_factory(classes)
if __name__ == "__main__":
register()