Home Coding, Scripting, Shaders

[Maxscript] Create bone between selections

polycounter lvl 7
Offline / Send Message
dg3duy polycounter lvl 7
This script to build bones based on selected objects works perfect if you are going to use it only once in the scene.
It gives error when using it again for the second time in the scene, apparently it is the way your array is built, as I do not have enough knowledge to solve it public here the question.
Is it possible to correct it to be able to use it as many times as one wants in a same scene?






  1. [code]
  2.  
  3. fn creaHuesoEntreSelecciones ancho alto tapersito=
  4. (
  5. bns=#()
  6. pts = selection as array
  7.  
  8. for i = 1 to pts.count-1 do
  9. (
  10. crearHuesos= bonesys.createbone (pts[i].pos) (pts[i+1].pos) [0,0,1]
  11. crearHuesos.name = ("huesito_"+i as string)
  12. )
  13.  
  14.  
  15. creaHuesoFinal=bonesys.createbone (pts[pts.count].pos) (pts[pts.count].pos) [0,0,1]
  16. creaHuesoFinal.name= ("huesito_"+pts.count as string)
  17.  
  18. bns = $huesito_* as array
  19. pts= selection as array
  20.  
  21. bns.width= ancho
  22. bns.Height= alto
  23. bns.taper= tapersito
  24.  
  25. for i = 1 to bns.count do
  26. (
  27. if bns[i] != bns[1] then bns[i].parent = bns[i-1]
  28. bns[i].position.controller =position_constraint()
  29. bns[i].position.controller.appendtarget pts[i] 100
  30. if bns[i]!= bns[bns.count] then bns[i].rotation.controller =lookAt_constraint target_axis:0 upnode_axis:2 StoUP_axis:2 lookat_vector_length:0 else bns[i].rotation.controller= Euler_XYZ()
  31. if bns[i] != bns[bns.count] then bns[i].rotation.controller.appendtarget pts[i+1] 100 else 0
  32. if bns[i]!= bns[bns.count] then bns[i].rotation.controller.pickupnode=pts[i] else 0
  33. if bns[i]!= bns[bns.count] then bns[i].rotation.controller.upnode_world=false else 0
  34. )
  35. --ROTACION DEL HUESO FINAL
  36. in coordsys bns[bns.count-1] bns[bns.count].rotation = eulerangles 0 0 0
  37. --TAMAÑO DEL HUESO FINAL
  38. bns[bns.count].length=bns[bns.count-1].length/20
  39. bns[bns.count].width= bns[bns.count-1].width/20
  40. bns[bns.count].height= bns[bns.count-1].height/20
  41. select bns
  42. )
  43. rollout CreaCadenaEntreSelecciones "CreateBones"
  44. (
  45. spinner UI_width "width" range:[1,100,2]
  46. spinner UI_height "height"range:[1,100,2]
  47. spinner UI_taper "taper" range:[1,100,2]
  48. button CreateBones "CreateBones"
  49. on CreateBones pressed do
  50. (
  51. if selection.count > 0 then
  52. (
  53. creaHuesoEntreSelecciones (UI_width.value) (UI_height.value) (UI_taper.value)
  54. )
  55. else messagebox "Seleccione mas de un objeto"
  56. )
  57. )
  58.  
  59. createDialog CreaCadenaEntreSelecciones
  60.  
  61. [/code]

Replies

  • Swordslayer
    Offline / Send Message
    Swordslayer interpolator
    1. try destroyDialog CreaCadenaEntreSelecciones catch()
    2. rollout CreaCadenaEntreSelecciones "Create Bones"
    3. (
    4. spinner UI_width "Width: " range:[1,100,2]
    5. spinner UI_height "Height: "range:[1,100,2]
    6. spinner UI_taper "Taper: " range:[1,100,2]
    7. button createBones "Create Bones"
    8.  
    9. fn creaHuesoEntreSelecciones pts width height taper =
    10. (
    11. local numPts = pts.count
    12. local prevBone = unsupplied
    13.  
    14. local bones = for i = 1 to numPts collect
    15. (
    16. local bone = ::Bone prefix:"huesito_" pos:pts[i].pos baseObject:(createInstance BoneGeometry width:width height:height taper:taper forceCreate:on) parent:prevBone boneEnable:on
    17. bone.position.controller = Position_Constraint()
    18. bone.position.controller.appendTarget pts[i] 100
    19. if isValidNode prevBone do prevBone.resetBoneStretch()
    20.  
    21. if i < numPts then
    22. (
    23. bone.rotation.controller = LookAt_Constraint target_axis:0 upnode_axis:2 upnode_world:off pickUpNode:pts[i] StoUP_axis:2 lookAt_vector_length:0
    24. bone.rotation.controller.appendTarget pts[i + 1] 100
    25. )
    26. else
    27. (
    28. in coordsys prevBone bone.rotation = quat 1
    29. bone.length = prevBone.length / 20
    30. bone.height /= 20
    31. bone.width /= 20
    32. )
    33.  
    34. prevBone = bone
    35. )
    36.  
    37. select bones
    38. )
    39.  
    40. on createBones pressed do
    41. if selection.count > 0 then with undo "Create Bones" on
    42. creaHuesoEntreSelecciones (selection as array) UI_width.value UI_height.value UI_taper.value
    43. else messagebox "Seleccione mas de un objeto"
    44. )
    45. createDialog CreaCadenaEntreSelecciones

  • dg3duy
    Offline / Send Message
    dg3duy polycounter lvl 7
    1. try destroyDialog CreaCadenaEntreSelecciones catch()
    2. rollout CreaCadenaEntreSelecciones "Create Bones"
    3. (
    4. spinner UI_width "Width: " range:[1,100,2]
    5. spinner UI_height "Height: "range:[1,100,2]
    6. spinner UI_taper "Taper: " range:[1,100,2]
    7. button createBones "Create Bones"
    8.  
    9. fn creaHuesoEntreSelecciones pts width height taper =
    10. (
    11. local numPts = pts.count
    12. local prevBone = unsupplied
    13.  
    14. local bones = for i = 1 to numPts collect
    15. (
    16. local bone = ::Bone prefix:"huesito_" pos:pts[i].pos baseObject:(createInstance BoneGeometry width:width height:height taper:taper forceCreate:on) parent:prevBone boneEnable:on
    17. bone.position.controller = Position_Constraint()
    18. bone.position.controller.appendTarget pts[i] 100
    19. if isValidNode prevBone do prevBone.resetBoneStretch()
    20.  
    21. if i < numPts then
    22. (
    23. bone.rotation.controller = LookAt_Constraint target_axis:0 upnode_axis:2 upnode_world:off pickUpNode:pts[i] StoUP_axis:2 lookAt_vector_length:0
    24. bone.rotation.controller.appendTarget pts[i + 1] 100
    25. )
    26. else
    27. (
    28. in coordsys prevBone bone.rotation = quat 1
    29. bone.length = prevBone.length / 20
    30. bone.height /= 20
    31. bone.width /= 20
    32. )
    33.  
    34. prevBone = bone
    35. )
    36.  
    37. select bones
    38. )
    39.  
    40. on createBones pressed do
    41. if selection.count > 0 then with undo "Create Bones" on
    42. creaHuesoEntreSelecciones (selection as array) UI_width.value UI_height.value UI_taper.value
    43. else messagebox "Seleccione mas de un objeto"
    44. )
    45. createDialog CreaCadenaEntreSelecciones

    Thank you very much! Now it works perfect
Sign In or Register to comment.