Lucas_3D

Apply SME Guard Clause

Jun 20th, 2024
126
0
Never
9
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. (
  2. Fn Apply_sme_material_to_selection=
  3. (
  4. sme_material_array = #()
  5.  
  6. -- Check if there is an active SME view
  7. if (sme.GetView (sme.activeView) == undefined) do
  8. (
  9. print "No SME View is active."
  10. return #stop
  11. )
  12.  
  13. -- Check if any objects are selected in the scene
  14. if (selection.count == 0) do
  15. (
  16. print "No objects are selected."
  17. return #stop
  18. )
  19.  
  20. -- Check if there are any nodes in the active SME view
  21. if ((trackViewNodes[#sme][(sme.activeView)].numSubs) == 0) do
  22. (
  23. print "No SME materials are available."
  24. return #stop
  25. )
  26.  
  27. -- Populate the material array
  28. viewNode = sme.GetView (sme.activeView)
  29. for n = 1 to trackViewNodes[#sme][(sme.activeView)].numSubs do
  30. (
  31. m = trackViewNodes[#sme][(sme.activeView)][n].reference
  32. b = viewNode.GetNodeByRef m
  33. if b.selected do append sme_material_array m
  34. )
  35.  
  36. -- Check if any materials were selected in the SME
  37. if sme_material_array.count == 0 do
  38. (
  39. print "No SME node selected."
  40. return #stop
  41. )
  42.  
  43. -- Ensure only one material is selected
  44. if sme_material_array.count > 1 do
  45. (
  46. print "Too many materials selected,\nSelect just 1 SME material."
  47. return #stop
  48. )
  49.  
  50. -- Confirm the selected SME node is a material
  51. if superClassOf sme_material_array[1] != material then
  52. (
  53. print "Selected SME node is not a material."
  54. return #stop
  55. )
  56.  
  57. for i in selection do
  58. (
  59. try
  60. (
  61. i.material = sme_material_array[1]
  62. ) catch()
  63. )
  64. )
  65.  
  66. Apply_sme_material_to_selection()
  67. )
  68.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment