PyAPI: use bl_rna_get_subclass for node API
Returns a default value instead of an error when the type isn't defined.
This commit is contained in:
parent
e44bf43f6c
commit
daf7aed849
@ -59,8 +59,11 @@ class NodeItem:
|
|||||||
return self._label
|
return self._label
|
||||||
else:
|
else:
|
||||||
# if no custom label is defined, fall back to the node type UI name
|
# if no custom label is defined, fall back to the node type UI name
|
||||||
cls = next(cls for cls in bpy.types.Node.__subclasses__() if cls.bl_rna.identifier == self.nodetype)
|
cls = bpy.types.Node.bl_rna_get_subclass(self.nodetype)
|
||||||
return cls.bl_rna.name
|
if cls is not None:
|
||||||
|
return cls.bl_rna.name
|
||||||
|
else:
|
||||||
|
return "Unknown"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def translation_context(self):
|
def translation_context(self):
|
||||||
@ -68,8 +71,11 @@ class NodeItem:
|
|||||||
return bpy.app.translations.contexts.default
|
return bpy.app.translations.contexts.default
|
||||||
else:
|
else:
|
||||||
# if no custom label is defined, fall back to the node type UI name
|
# if no custom label is defined, fall back to the node type UI name
|
||||||
cls = next(cls for cls in bpy.types.Node.__subclasses__() if cls.bl_rna.identifier == self.nodetype)
|
cls = bpy.types.Node.bl_rna_get_subclass(self.nodetype)
|
||||||
return cls.bl_rna.translation_context
|
if cls is not None:
|
||||||
|
return cls.bl_rna.translation_context
|
||||||
|
else:
|
||||||
|
return bpy.app.translations.contexts.default
|
||||||
|
|
||||||
# NB: is a staticmethod because called with an explicit self argument
|
# NB: is a staticmethod because called with an explicit self argument
|
||||||
# NodeItemCustom sets this as a variable attribute in __init__
|
# NodeItemCustom sets this as a variable attribute in __init__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user