PyAPI: use bl_rna_get_subclass for node API
authorCampbell Barton <ideasman42@gmail.com>
Thu, 7 Sep 2017 14:03:01 +0000 (00:03 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 7 Sep 2017 14:03:01 +0000 (00:03 +1000)
Returns a default value instead of an error when the type isn't defined.

release/scripts/modules/nodeitems_utils.py

index 4be6e340760844065fae3e15e8fc88e84e6fd81f..7dc456f6c984d9477557ae333a73a74fc9b7d98c 100644 (file)
@@ -59,8 +59,11 @@ class NodeItem:
             return self._label
         else:
             # 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)
-            return cls.bl_rna.name
+            cls = bpy.types.Node.bl_rna_get_subclass(self.nodetype)
+            if cls is not None:
+                return cls.bl_rna.name
+            else:
+                return "Unknown"
 
     @property
     def translation_context(self):
@@ -68,8 +71,11 @@ class NodeItem:
             return bpy.app.translations.contexts.default
         else:
             # 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)
-            return cls.bl_rna.translation_context
+            cls = bpy.types.Node.bl_rna_get_subclass(self.nodetype)
+            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
     # NodeItemCustom sets this as a variable attribute in __init__