1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
6 Object / Material Indices Panel
8 When working with ID Masks in the Nodes Editor, is hard to follow track
9 of which objects/materials have which ID.
10 This adds a panel on the sidebar when an ID Mask node is selected.
11 The active object is highlighted between [square brackets] On the Nodes
12 Editor's sidebar, when an ID Mask node is selected.
18 class AMTH_NODE_PT_indices(bpy
.types
.Panel
):
19 bl_space_type
= "NODE_EDITOR"
21 bl_label
= "Object / Material Indices"
22 bl_options
= {"DEFAULT_CLOSED"}
25 def poll(cls
, context
):
26 node
= context
.active_node
27 return node
and node
.type == "ID_MASK"
29 def draw(self
, context
):
32 objects
= bpy
.data
.objects
33 materials
= bpy
.data
.materials
34 node
= context
.active_node
40 if context
.active_object
:
41 ob_act
= context
.active_object
46 if ob
and ob
.pass_index
> 0:
49 if ma
and ma
.pass_index
> 0:
51 row
= layout
.row(align
=True)
52 row
.prop(node
, "index", text
="Mask Index")
53 row
.prop(node
, "use_matching_indices", text
="Only Matching IDs")
57 if not show_ob_id
and not show_ma_id
:
59 text
="No objects or materials indices so far.", icon
="INFO")
62 split
= layout
.split()
64 col
.label(text
="Object Name")
65 split
.label(text
="ID Number")
68 icon
= "OUTLINER_DATA_" + ob
.type
70 icon
= "LIBRARY_DATA_DIRECT"
71 elif ob
.is_library_indirect
:
72 icon
= "LIBRARY_DATA_INDIRECT"
74 if ob
and node
.use_matching_indices \
75 and ob
.pass_index
== node
.index \
76 and ob
.pass_index
!= 0:
79 text
="[{}]".format(ob
.name
)
80 if ob_act
and ob
.name
== ob_act
.name
else ob
.name
,
82 row
.label(text
="%s" % ob
.pass_index
)
85 elif ob
and not node
.use_matching_indices \
86 and ob
.pass_index
> 0:
90 text
="[{}]".format(ob
.name
)
91 if ob_act
and ob
.name
== ob_act
.name
else ob
.name
,
93 row
.label(text
="%s" % ob
.pass_index
)
96 if node
.use_matching_indices
and not matching_ids
:
97 row
.label(text
="No objects with ID %s" %
98 node
.index
, icon
="INFO")
103 split
= layout
.split()
105 col
.label(text
="Material Name")
106 split
.label(text
="ID Number")
114 icon
= "LIBRARY_DATA_DIRECT"
115 if ma
.is_library_indirect
:
116 icon
= "LIBRARY_DATA_INDIRECT"
118 if ma
and node
.use_matching_indices \
119 and ma
.pass_index
== node
.index \
120 and ma
.pass_index
!= 0:
122 row
.label(text
="%s" % ma
.name
, icon
=icon
)
123 row
.label(text
="%s" % ma
.pass_index
)
126 elif ma
and not node
.use_matching_indices \
127 and ma
.pass_index
> 0:
130 row
.label(text
="%s" % ma
.name
, icon
=icon
)
131 row
.label(text
="%s" % ma
.pass_index
)
134 if node
.use_matching_indices
and not matching_ids
:
135 row
.label(text
="No materials with ID %s" %
136 node
.index
, icon
="INFO")
140 bpy
.utils
.register_class(AMTH_NODE_PT_indices
)
144 bpy
.utils
.unregister_class(AMTH_NODE_PT_indices
)