Monday 18 March 2013

Adjust Spread (between objects)

If you want to increase or reduce the distance between objects.


Usage
  • select several objects
  • run script
  • adjust slider amount
    • values greater than 0 increase spread
    • values less than 0 reduce spread (bunching objects)
  • close dialogue
Limitations
  • Does not take kindly to you changing the selection while the dialogue is still open
  • Does not count as an "undo step" (but setting adjust to 0 puts them back where you started)
Updates
  • introduced axis choice (X, Y, Z, X and Y or All)
  • added an undo point on running the script
  • introduced selection lock and other measures to reduce chance of "user error"
   
  
-- MixeScript snippet: Adjust Spread
-- adjusts distance between objects using the center position of those objects

--USAGE
-- select several objects
-- run script
-- adjust slider amount
 --values greater than 0 increase spread
 --values less than 0 reduce spread (bunching objects)
-- close script window
 
--LIMITATIONS
--Does not take kindly to you changing the selection while the dialogue is still open
--Does not count as an "undo step" (but setting adjust to 0 puts them back where you started)

 
max spacebar -- lock selection
 
with undo on (print "undo point")
 
centerpos = selection.center
objarray = getcurrentselection()
objpositions = #()
for obj in objarray do (append objpositions (obj.position - centerpos))

rollout Spreader "Spreader" width:100 height:130
(
  spinner spn_spread "Spread" pos:[0,11] width:90 height:16 range:[-100,100,0] scale:0.01 
 radioButtons rdo_axis "" pos:[7,40] width:40 height:64 labels:#("X", "Y", "Z", "X and Y", "All") default:5

  on spn_spread changed amt do 
  (
    for i = 1 to objarray.count do
    (
     if rdo_axis.state == 1 then ( --x
    objarray[i].position = [centerpos.x + (objpositions[i].x * (1+amt)),objarray[i].position.y,objarray[i].position.z]
     )
     if rdo_axis.state == 2 then ( --y
    objarray[i].position = [objarray[i].position.x,centerpos.y + (objpositions[i].y * (1+amt)),objarray[i].position.z]
     )
     if rdo_axis.state == 3 then ( --z
    objarray[i].position = [objarray[i].position.x,objarray[i].position.y,centerpos.z + (objpositions[i].z * (1+amt))]
     )
     if rdo_axis.state == 4 then ( --x & y
    objarray[i].position = [centerpos.x + (objpositions[i].x * (1+amt)),centerpos.y + (objpositions[i].y * (1+amt)),objarray[i].position.z]
     )
     if rdo_axis.state == 5 then ( --all
    objarray[i].position = centerpos + (objpositions[i] * (1+amt))
     )
   )
  )
  
  on rdo_axis changed changedto do 
  (
   spn_spread.value = 0.0
     for i = 1 to objarray.count do
   (objarray[i].position = objpositions[i] + centerpos)
   
  )
  
  on Spreader close do 
 (
  max spacebar --unlock selection
 )
 
) --end of rollout

if selection.count == 0 then 
(messagebox "please make a selection first.") 
else 
(
 undo on (createDialog Spreader dlg_Spreader)
)
  

1 comment:

  1. How is this script still so useful all these years later! Great for sorting out messy client models. Thanks again Mike.

    ReplyDelete