versioning.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. #Versioning Tasks
  2. # this will be the new versioning system, and will deprecate the old SOCKETS_ADDED and such
  3. from bpy.types import Node, NodeSocket
  4. from bpy.app import version as bpy_version
  5. from .utilities import (prRed, prGreen, prPurple, prWhite,
  6. prOrange,
  7. wrapRed, wrapGreen, wrapPurple, wrapWhite,
  8. wrapOrange,)
  9. def version_upgrade_very_old(*args, **kwargs):
  10. node = kwargs['node']
  11. current_major_version = node.id_data.mantis_version[0]
  12. current_minor_version = node.id_data.mantis_version[1]
  13. if current_major_version > 0: return# major version must be 0
  14. if current_minor_version > 11: return# minor version must be 12 or less
  15. # this is the old node update, very inneficient and strange and badly organized
  16. NODES_REMOVED=["xFormRootNode"]
  17. # Node bl_idname, # Socket Name
  18. SOCKETS_REMOVED=[("UtilityDriverVariable", "Transform Channel"),
  19. ("xFormRootNode","World Out"),
  20. ("UtilitySwitch","xForm"),
  21. ("LinkDrivenParameter", "Enable")]
  22. # Node Class #Prior bl_idname # prior name # new bl_idname # new name, # Multi
  23. SOCKETS_RENAMED=[ ("LinkDrivenParameter", "DriverSocket", "Driver", "FloatSocket", "Value", False),
  24. ("DeformerHook", "IntSocket", "Index", "UnsignedIntSocket", "Point Index", False),
  25. ("SchemaConstOutput", "IntSocket", "Expose when N==", "UnsignedIntSocket", "Expose at Index", False),]
  26. # NODE CLASS NAME IN_OUT SOCKET TYPE SOCKET NAME INDEX MULTI DEFAULT
  27. SOCKETS_ADDED=[("DeformerMorphTargetDeform", 'INPUT', 'BooleanSocket', "Use Shape Key", 1, False, False),
  28. ("DeformerMorphTargetDeform", 'INPUT', 'BooleanSocket', "Use Offset", 2, False, True),
  29. ("UtilityFCurve", 'INPUT', "eFCrvExtrapolationMode", "Extrapolation Mode", 0, False, 'CONSTANT'),
  30. ("LinkCopyScale", 'INPUT', "BooleanSocket", "Additive", 3, False, False),
  31. ("DeformerHook", 'INPUT', "FloatFactorSocket", "Influence",3, False, 1.0),
  32. ("DeformerHook", 'INPUT', "UnsignedIntSocket", "Spline Index", 2, False, 0),
  33. ("DeformerHook", 'INPUT', "BooleanSocket", "Auto-Bezier", 5, False, True),
  34. ("UtilityCompare", 'INPUT', "EnumCompareOperation", "Comparison", 0, False, 'EQUAL'),
  35. ("UtilityMatrixFromCurve", 'INPUT', "UnsignedIntSocket", "Spline Index", 1, False, 0),
  36. ("UtilityMatricesFromCurve", 'INPUT', "UnsignedIntSocket", "Spline Index", 1, False, 0),
  37. ("UtilityPointFromCurve", 'INPUT', "UnsignedIntSocket", "Spline Index", 1, False, 0),
  38. ("LinkCopyScale", 'INPUT', "FloatFactorSocket", "Power", 5, False, 1.0),
  39. ]
  40. rename_jobs = []
  41. node_tree = kwargs['node_tree']
  42. try:
  43. if node.bl_idname in NODES_REMOVED:
  44. print(f"INFO: removing node {node.name} of type {node.bl_idname} because it has been deprecated.")
  45. node.inputs.remove(socket)
  46. return
  47. for i, socket in enumerate(node.inputs.values()):
  48. if (node.bl_idname, socket.identifier) in SOCKETS_REMOVED:
  49. print(f"INFO: removing socket {socket.identifier} of node {node.name} of type {node.bl_idname} because it has been deprecated.")
  50. node.inputs.remove(socket)
  51. for old_class, old_bl_idname, old_name, new_bl_idname, new_name, multi in SOCKETS_RENAMED:
  52. if (node.bl_idname == old_class and socket.bl_idname == old_bl_idname and socket.name == old_name):
  53. rename_jobs.append((socket, i, new_bl_idname, new_name, multi))
  54. for i, socket in enumerate(node.outputs.values()):
  55. if (node.bl_idname, socket.identifier) in SOCKETS_REMOVED:
  56. print(f"INFO: removing socket {socket.identifier} of node {node.name} of type {node.bl_idname} because it has been deprecated.")
  57. node.outputs.remove(socket)
  58. for old_class, old_bl_idname, old_name, new_bl_idname, new_name, multi in SOCKETS_RENAMED:
  59. if (node.bl_idname == old_class and socket.bl_idname == old_bl_idname and socket.name == old_name):
  60. rename_jobs.append((socket, i, new_bl_idname, new_name, multi))
  61. for bl_idname, in_out, socket_type, socket_name, index, use_multi_input, default_val in SOCKETS_ADDED:
  62. if node.bl_idname != bl_idname:
  63. continue
  64. if in_out == 'INPUT' and node.inputs.get(socket_name) is None:
  65. print(f"INFO: adding socket \"{socket_name}\" of type {socket_type} to node {node.name} of type {node.bl_idname}.")
  66. s = node.inputs.new(socket_type, socket_name, use_multi_input=use_multi_input)
  67. try:
  68. s.default_value = default_val
  69. except AttributeError:
  70. pass # the socket is read-only
  71. node.inputs.move(len(node.inputs)-1, index)
  72. socket_map = None
  73. if rename_jobs:
  74. from .utilities import get_socket_maps
  75. socket_maps = get_socket_maps(node)
  76. for socket, socket_index, new_bl_idname, new_name, multi in rename_jobs:
  77. old_id = socket.identifier
  78. print (f"Renaming socket {socket.identifier} to {new_name} in node {node.name}")
  79. from .utilities import do_relink
  80. if socket.is_output:
  81. index = 1
  82. in_out = "OUTPUT"
  83. node.outputs.remove(socket)
  84. s = node.outputs.new(new_bl_idname, new_name, identifier=new_name, use_multi_input=multi)
  85. node.outputs.move(len(node.outputs)-1, socket_index)
  86. socket_map = socket_maps[1]
  87. else:
  88. index = 0
  89. in_out = "INPUT"
  90. node.inputs.remove(socket)
  91. s = node.inputs.new(new_bl_idname, new_name, identifier=new_name, use_multi_input=multi)
  92. node.inputs.move(len(node.inputs)-1, socket_index)
  93. socket_map = socket_maps[0]
  94. socket_map[new_name] = socket_map[old_id]
  95. if new_name != old_id: del socket_map[old_id] # sometimes rename just changes the socket type or multi
  96. do_relink(node, s, socket_map)
  97. except Exception as e:
  98. prRed(f"Error updating version in node: {node.id_data.name}::{node.name}; see error:")
  99. print(e)
  100. def version_upgrade_bone_0_12_0_from_older(*args, **kwargs):
  101. # we need to check if it has an array collection input and a color input
  102. # then we need to solve each task
  103. node = kwargs['node']
  104. current_major_version = node.id_data.mantis_version[0]
  105. current_minor_version = node.id_data.mantis_version[1]
  106. if current_major_version > 0: # major version must be 0
  107. return
  108. if current_minor_version >= 12: # minor version must be 11 or less
  109. return
  110. # sub version doesn't matter since any subversion of 11 should trigger this task
  111. try:
  112. collection_input_is_array = node.inputs['Bone Collection'].is_multi_input
  113. if not collection_input_is_array: # it must be made into an array!
  114. prPurple(f"Updating \"Bone Collection\" Socket in {node.name}")
  115. from .utilities import get_socket_maps
  116. socket_maps = get_socket_maps(node)
  117. socket_map = socket_maps[0]
  118. for i, socket in enumerate(node.inputs):
  119. if socket.name == 'Bone Collection': break
  120. old_id = socket.identifier
  121. # it is an input
  122. node.inputs.remove(socket)
  123. s = node.inputs.new('BoneCollectionSocket', 'Bone Collection',
  124. identifier='Bone Collection', use_multi_input=True)
  125. node.inputs.move(len(node.inputs)-1, i)
  126. socket_map_from_old_socket = socket_map[old_id]
  127. # there seems to be an error in do_relink
  128. # gonna do it directly instead
  129. if isinstance(socket_map_from_old_socket, list):
  130. for map_info in socket_map_from_old_socket:
  131. if isinstance(map_info, Node ):
  132. l = node.id_data.links.new(input=map_info.outputs[0], output=s)
  133. elif isinstance(map_info, NodeSocket):
  134. l = node.id_data.links.new(input=map_info, output=s)
  135. else:
  136. s.default_value = socket_map_from_old_socket
  137. if node.inputs.get('Color') is None:
  138. prPurple(f"Adding \"Color\" Socket to {node.name}")
  139. s = node.inputs.new('ColorSetSocket', 'Color',)
  140. node.inputs.move(len(node.inputs)-1, 22)
  141. except Exception as e:
  142. prRed(f"Error updating version in node: {node.id_data.name}::{node.name}; see error:")
  143. print(e)
  144. def up_0_12_1_add_inherit_color(*args, **kwargs):
  145. # add an inherit color input.
  146. node = kwargs['node']
  147. current_major_version = node.id_data.mantis_version[0]
  148. current_minor_version = node.id_data.mantis_version[1]
  149. current_sub_version = node.id_data.mantis_version[2]
  150. if current_major_version > 0: return# major version must be 0
  151. if current_minor_version > 12: return# minor version must be 12 or less
  152. if current_minor_version == 12 and current_sub_version > 9: return # sub version must be 8 or less
  153. # I am having it do 8 or less because there was a bug in this function prior to 9
  154. # sub version doesn't matter since any subversion of 11 should trigger this task
  155. prPurple(f"Adding \"Inherit Color\" socket to {node.name}")
  156. try:
  157. inh_color = node.inputs.get('Inherit Color')
  158. if inh_color and inh_color.bl_idname != 'BooleanSocket':
  159. node.inputs.remove(inh_color)
  160. inh_color = None
  161. if inh_color is None:
  162. s = node.inputs.new('BooleanSocket', 'Inherit Color',)
  163. node.inputs.move(len(node.inputs)-1, 23)
  164. s.default_value=True
  165. except Exception as e:
  166. prRed(f"Error updating version in node: {node.id_data.name}::{node.name}; see error:")
  167. print(e)
  168. def up_0_12_13_add_widget_scale(*args, **kwargs):
  169. # add an inherit color input.
  170. node = kwargs['node']
  171. current_major_version = node.id_data.mantis_version[0]
  172. current_minor_version = node.id_data.mantis_version[1]
  173. current_sub_version = node.id_data.mantis_version[2]
  174. if current_major_version > 0: return# major version must be 0
  175. if current_minor_version > 12: return# minor version must be 12 or less
  176. if current_minor_version == 12 and current_sub_version > 12: return
  177. # sub version must be 12 or less
  178. prPurple(f"Adding \"Scale\" socket to {node.name}")
  179. try:
  180. scale = node.inputs.get('Scale')
  181. if scale is None:
  182. s = node.inputs.new('VectorScaleSocket', 'Scale',)
  183. s.default_value=[1.0,1.0,1.0]
  184. node.inputs.move(len(node.inputs)-1, 1)
  185. except Exception as e:
  186. prRed(f"Error updating version in node: {node.id_data.name}::{node.name}; see error:")
  187. print(e)
  188. # versioning tasks that involve Blender versions rather than Mantis versions:
  189. error_description_4_5_0_LTS = 'There is a bug in Blender 4.5.0 LTS, that is why these sockets are blue.'\
  190. ' This will be fixed in future Blender versions.'
  191. def cleanup_4_5_0_LTS_interface_workaround(*args, **kwargs):
  192. # this is a function for cleaning up the workaround up above
  193. tree = kwargs['tree']
  194. if bpy_version == (4,5,0): return
  195. if not hasattr(tree, "interface_helper"):
  196. return
  197. import json
  198. try:
  199. interface_helper = json.loads(tree.interface_helper)
  200. except:
  201. return # this should mean it was never a problem to begin with.
  202. prPurple(f"Restoring Tree Interface for {tree.name}.")
  203. for interface_item in tree.interface.items_tree:
  204. if interface_item.item_type == 'PANEL': continue
  205. # now we need to restore the socket types, which are in the interface helper
  206. # keep the interface stuff around, I'll use it for marking arrays in the future
  207. int_info = interface_helper[interface_item.identifier]
  208. socket_type = int_info['bl_socket_idname']
  209. interface_item.socket_type = socket_type
  210. if interface_item.description == error_description_4_5_0_LTS:
  211. interface_item.description = ''
  212. # that should be enough!
  213. def up_0_12_25_replace_floor_offset_type(*args, **kwargs):
  214. # add an inherit color input.
  215. node = kwargs['node']
  216. current_major_version = node.id_data.mantis_version[0]
  217. current_minor_version = node.id_data.mantis_version[1]
  218. current_sub_version = node.id_data.mantis_version[2]
  219. if current_major_version > 0: return# major version must be 0
  220. if current_minor_version > 12: return# minor version must be 12 or less
  221. if current_minor_version == 12 and current_sub_version > 24: return
  222. from .utilities import get_socket_maps, do_relink
  223. socket_maps = get_socket_maps(node)
  224. prPurple(f"Fixing \"Offset\" socket in {node.name}")
  225. try:
  226. offset = node.inputs["Offset"]
  227. node.inputs.remove(offset)
  228. s = node.inputs.new('FloatSocket', 'Offset',)
  229. node.inputs.move(len(node.inputs)-1, 2)
  230. do_relink(node, s, socket_maps[0])
  231. except Exception as e:
  232. prRed(f"Error updating version in node: {node.id_data.name}::{node.name}; see error:")
  233. print(e)
  234. def get_absolute_location(node): # us9ng this for version compatibility
  235. location = node.location.copy() # FUTURE: deprecate old blenders and use absolute_location
  236. while(node.parent):
  237. node = node.parent
  238. location+= node.location
  239. return location
  240. def up_0_13_0_new_custom_prop_node(*args, **kwargs):
  241. tree, node = kwargs['node_tree'], kwargs['node']
  242. current_major_version = tree.mantis_version[0]
  243. if current_major_version > 0: return# major version must be 0
  244. current_minor_version = tree.mantis_version[1]
  245. if current_minor_version >= 13: return# minor version must be 12 or less
  246. remove_me, prop_nodes = [], []
  247. from .xForm_nodes_ui import xFormBoneNode
  248. if isinstance(node, xFormBoneNode):
  249. for custom_input in node.inputs:
  250. if 'Parameter' not in custom_input.bl_idname:
  251. continue
  252. custom_prop_node = tree.nodes.new('UtilityCustomProperty')
  253. prop_type = None
  254. if custom_input.bl_idname == 'ParameterBoolSocket':
  255. prop_type = 'BOOL'
  256. custom_prop_node.inputs['Default (Bool)'].default_value = getattr(custom_input, "default_value")
  257. elif custom_input.bl_idname == 'ParameterIntSocket':
  258. prop_type = 'INT'
  259. custom_prop_node.inputs['Default (Int)'].default_value = int( getattr(custom_input, "default_value") )
  260. custom_prop_node.inputs['Min (Int)'].default_value = int( getattr(custom_input, "min") )
  261. custom_prop_node.inputs['Max (Int)'].default_value = int( getattr(custom_input, "max") )
  262. custom_prop_node.inputs['Soft Min (Int)'].default_value = int( getattr(custom_input, "soft_min") )
  263. custom_prop_node.inputs['Soft Max (Int)'].default_value = int( getattr(custom_input, "soft_max") )
  264. elif custom_input.bl_idname == 'ParameterFloatSocket':
  265. prop_type = 'FLOAT'
  266. custom_prop_node.inputs['Default (Float)'].default_value = getattr(custom_input, "default_value")
  267. custom_prop_node.inputs['Min (Float)'].default_value = getattr(custom_input, "min")
  268. custom_prop_node.inputs['Max (Float)'].default_value = getattr(custom_input, "max")
  269. custom_prop_node.inputs['Soft Min (Float)'].default_value = getattr(custom_input, "soft_min")
  270. custom_prop_node.inputs['Soft Max (Float)'].default_value = getattr(custom_input, "soft_max")
  271. elif custom_input.bl_idname == 'ParameterVectorSocket':
  272. prop_type = 'VECTOR'
  273. custom_prop_node.inputs['Default (Vector)'].default_value = getattr(custom_input, "default_value")
  274. custom_prop_node.inputs['Min (Float)'].default_value = getattr(custom_input, "min")
  275. custom_prop_node.inputs['Max (Float)'].default_value = getattr(custom_input, "max")
  276. custom_prop_node.inputs['Soft Min (Float)'].default_value = getattr(custom_input, "soft_min")
  277. custom_prop_node.inputs['Soft Max (Float)'].default_value = getattr(custom_input, "soft_max")
  278. elif custom_input.bl_idname == 'ParameterStringSocket':
  279. prop_type = 'STRING'
  280. custom_prop_node.inputs['Default (String)'].default_value = getattr(custom_input, "default_value")
  281. custom_prop_node.inputs['Name'].default_value = custom_input.name
  282. custom_prop_node.inputs['Type'].default_value = prop_type
  283. prop_nodes.append(custom_prop_node)
  284. remove_me.append(custom_input)
  285. while remove_me:
  286. custom_input = remove_me.pop()
  287. node.inputs.remove(custom_input)
  288. new_input = node.inputs.new("CustomPropSocket", "Custom Properties", use_multi_input=True)
  289. from mathutils import Vector
  290. for i, prop_node in enumerate(prop_nodes):
  291. tree.links.new(input=prop_node.outputs[0], output=new_input)
  292. prop_node.location = get_absolute_location(node)
  293. prop_node.location = prop_node.location - Vector((180, -260*i))
  294. prop_node.select = False # it is annoying to select them all by default
  295. else: # just need to add the socket.
  296. new_input = node.inputs.new("CustomPropSocket", "Custom Properties", use_multi_input=True)
  297. def schema_enable_custom_interface_types(*args, **kwargs):
  298. # return
  299. tree = kwargs['tree']
  300. current_major_version = tree.mantis_version[0]
  301. current_minor_version = tree.mantis_version[1]
  302. current_sub_version = tree.mantis_version[2]
  303. if current_major_version > 0: return# major version must be 0
  304. if current_minor_version >= 13: return# minor version must be 12 or less
  305. # we need to set the new interface values on the schema interface stuff
  306. prGreen(f"Updating Schema tree {tree.name} to support new, improved UI!")
  307. tree.do_live_update = False
  308. for n in tree.nodes:
  309. if hasattr(n, "is_updating"):
  310. n.is_updating = True
  311. try:
  312. for item in tree.interface.items_tree:
  313. if item.item_type == 'PANEL':
  314. continue
  315. parent_name = 'Constant'
  316. if item.parent:
  317. parent_name=item.parent.name
  318. if hasattr(item, "is_array"):
  319. # if is_array exists we're in the custom interface class
  320. # so we'll assume the other attributes exist
  321. if parent_name == 'Array':
  322. item.is_array = True
  323. if parent_name == 'Connection':
  324. item.is_array = False
  325. item.is_connection=True
  326. item.connected_to=item.name
  327. # since heretofore it has been a requirement that the names match
  328. except Exception as e:
  329. prRed(f"Error updating version in tree: {tree.name}; see error:")
  330. print(e)
  331. finally:
  332. for n in tree.nodes:
  333. if hasattr(n, "is_updating"):
  334. n.is_updating = False
  335. tree.do_live_update = True
  336. # since this is basically the same operation, just do it all together
  337. def update_fcurve_and_armature_node_to_multi_socket(*args, **kwargs):
  338. node = kwargs['node']
  339. prRed("BEPIS")
  340. live_updates = node.id_data.do_live_update
  341. node.id_data.do_live_update = False
  342. # First we have to get the socket maps and re-init the sockets
  343. from .utilities import get_socket_maps, do_relink
  344. sockets_in, _sockets_out = get_socket_maps(node,)
  345. node.inputs.clear(); node.outputs.clear()
  346. node.init_sockets(node.socket_templates)
  347. convert_keys = {'UtilityFCurve' : [ 'Keyframe', ],
  348. 'LinkArmature' : [ 'Target', 'Weight', ], }
  349. try:
  350. new_sockets_in = {}
  351. print (convert_keys[node.bl_idname])
  352. for convert_key in convert_keys[node.bl_idname]:
  353. for socket_name, links in sockets_in.items():
  354. if links is None: continue
  355. if convert_key+'.' in socket_name:
  356. print (socket_name, links)
  357. if new_sockets_in.get(convert_key+'s'):
  358. # has to be in this order to come back alright.
  359. # assuming, that is, that the keys are sorted. they should be.
  360. new_sockets_in[convert_key+'s'] = sockets_in[socket_name] + new_sockets_in[convert_key+'s']
  361. else:
  362. new_sockets_in[convert_key+'s'] = sockets_in[socket_name]
  363. prWhite (new_sockets_in[convert_key+'s'])
  364. do_relink(node, node.inputs[convert_key+'s'], new_sockets_in, in_out="INPUT",)
  365. delete_me = []
  366. for socket in node.inputs:
  367. if convert_key+'.' in socket.name:
  368. delete_me.append(socket)
  369. for socket in delete_me:
  370. node.inputs.remove(socket)
  371. finally:
  372. node.id_data.do_live_update = live_updates
  373. versioning_tasks = [
  374. # node bl_idname task required keyword arguments
  375. (['ALL'], version_upgrade_very_old, ['node_tree', 'node'],),
  376. (['xFormBoneNode'], version_upgrade_bone_0_12_0_from_older, ['node'],),
  377. (['xFormBoneNode'], up_0_12_1_add_inherit_color, ['node'],),
  378. (['MantisTree', 'SchemaTree'], cleanup_4_5_0_LTS_interface_workaround, ['tree']),
  379. (['InputWidget'], up_0_12_13_add_widget_scale, ['node']),
  380. (['LinkFloor'], up_0_12_25_replace_floor_offset_type, ['node']),
  381. (['XFORM'], up_0_13_0_new_custom_prop_node, ['node', 'node_tree']),
  382. (['SchemaTree'], schema_enable_custom_interface_types, ['tree']),
  383. (['UtilityFCurve', 'LinkArmature'],
  384. update_fcurve_and_armature_node_to_multi_socket, ['node']),
  385. ]
  386. # WORKAROUNDS for bugs should go here:
  387. # 4.5.0 LTS valid socket types bug:
  388. def workaround_4_5_0_interface_update(tree, name, in_out, sock_type, parent_name, do_parent=False):
  389. # TODO: dedupe this code from i_o.py
  390. prRed("There is a bug in Blender 4.5.0 regarding node-group interface sockets. Working around it.")
  391. sock = tree.interface.new_socket(name=name, in_out=in_out, socket_type="NodeSocketGeometry")
  392. import json
  393. interface_helper = {} # initialize it if it is empty
  394. if tree.interface_helper: # may be empty, check here
  395. interface_helper = json.loads(tree.interface_helper)
  396. error_message = error_description_4_5_0_LTS
  397. interface_helper[sock.identifier] = {
  398. 'name' : sock.name,
  399. 'identifier' : sock.identifier,
  400. 'in_out' : sock.in_out,
  401. 'socket_type' : sock_type,
  402. 'bl_socket_idname' : sock_type,
  403. 'mantis_socket_category' : parent_name,
  404. 'description' : error_message,
  405. }
  406. sock.description = error_message # this tells the user why the socket looks weird.
  407. tree.interface_helper = json.dumps(interface_helper)
  408. if do_parent and (parent := tree.interface.items_tree.get(parent_name)):
  409. tree.interface.move_to_parent(
  410. sock,
  411. parent,
  412. 0, # what to do here?
  413. )
  414. return sock
  415. def socket_add_workaround_for_4_5_0_LTS(item, socket_collection, multi):
  416. import json
  417. tree = item.id_data
  418. interface_helper = json.loads(tree.interface_helper)
  419. socket_info = interface_helper.get(item.identifier)
  420. if not socket_info: raise RuntimeError(f"There has been an error adding the socket {item.name}")
  421. s = socket_collection.new(
  422. type=socket_info['bl_socket_idname'],
  423. name=item.name, # in case the user has changed it
  424. identifier=item.identifier,
  425. use_multi_input=multi, )
  426. return s