Parcourir la source

fix: 5.0 compatibility fix

Joseph Brandenburg il y a 11 mois
Parent
commit
1fb2ad3c67
2 fichiers modifiés avec 6 ajouts et 10 suppressions
  1. 1 1
      i_o.py
  2. 5 9
      utilities.py

+ 1 - 1
i_o.py

@@ -366,7 +366,7 @@ def get_socket_data(socket, ignore_if_default=False):
     if socket.bl_idname == "EnumMetaBoneSocket":
         socket_data["bone"] = socket.bone
     if socket.bl_idname in ["EnumMetaBoneSocket", "EnumMetaRigSocket", "EnumCurveSocket"]:
-        if sp := socket.get("search_prop"): # may be None
+        if hasattr(socket, "search_prop") and (sp := socket.search_prop): # may be None
             socket_data["search_prop"] = sp.name # this is an object.
     #
     if hasattr(socket, "default_value"):

+ 5 - 9
utilities.py

@@ -145,18 +145,14 @@ def get_socket_maps(node, force=False):
                     keep_sockets.append(other_socket)
                 map[sock.identifier]= keep_sockets
             elif hasattr(sock, "default_value"):
-                # NOTE: Blender 5.0 and greater have removed sock.get("attr").
-                #    I hope getattr does exactly the same thing, but I worry about changes.
-                #    If I remember correctly, I used this particular syntax because the behaviour
-                #    of sock.get("attr") vs. getattr(sock, "attr") was affected by the file load time
-                #    and the former could retrieve the data while the latter lost it.
-                #    However, since, IIRC, this only happened in the first case with curves
-                #    I feel confident it will work everywhere else.
-                if sock.bl_idname == "EnumCurveSocket" and getattr(sock, "default_value") is None:
+                # in blender 5.0 we have to use sock.default_value insted of sock.get("default_value") :/
+                if sock.bl_idname == "EnumCurveSocket" and sock.default_value is None:
                     # HACK I need to add this special case because during file-load,
                     #  this value is None and should not be altered until it is set once.
                     continue
-                elif "Enum" in sock.bl_idname and isinstance(getattr(sock, "default_value"), int):
+                if sock.default_value is not None:
+                    val = getattr(sock, "default_value")
+                elif "Enum" in sock.bl_idname and isinstance(sock.get("default_value"), int):
                     continue # for string enum properties that have not yet initialized (at startup)
                 elif (val := sock.default_value) is not None:
                     pass