nik684

AssignRandomId

May 11th, 2025
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. (
  2. fn GetElements obj =
  3. (
  4. if not iskindof obj Editable_Poly do return #()
  5. getelem = polyop.getElementsUsingFace /* <Poly poly> <facelist> fence:<fence_facelist> */
  6. local faces_done = #{}
  7. local element_arr = #()
  8. for face=1 to obj.numfaces where not faces_done[face] do
  9. (
  10. elemfaces = getelem obj #{face}
  11. faces_done += elemfaces
  12. append element_arr elemfaces
  13. )
  14. element_arr
  15. )
  16.  
  17. fn AssignRandomId obj =
  18. (
  19. local elem_arr = GetElements obj
  20. local start_id = 1
  21. local end_id = elem_arr.count + start_id - 1
  22. local id_arr = for i=start_id to end_id collect i
  23. undo "random id" on
  24. (
  25. for elem in elem_arr do
  26. (
  27. local index = random 1 id_arr.count
  28. local id = id_arr[index]
  29. deleteitem id_arr index
  30. polyop.setFaceMatID obj elem id
  31. )
  32. )
  33. )
  34. AssignRandomId $
  35. )
Advertisement
Add Comment
Please, Sign In to add comment