PDA

View Full Version : Swap Objects


thatoneguy
06-06-2007, 12:35 AM
Little handy script. Select a series of objects and execute. It will then have them trade places in the order they were selected with the last selected object going to the position and rotation of the first.

One thing I would like to add but haven't figured out how to do (maybe one of you smart individuals can help me with this) is to have it do different things when pressed while the CTRL or ALT button is pressed.

So if you hold down CTRL have it only swap positions. And if you hold down ALT only transfer rotations. I can use the keyboard.altpressed and keyboard.controlpressed global variables however I can't push a macroscript button while either key is depressed. Any ideas on how to work around that? I don't want to slow down the ease of use.


macroScript Swapper
category:"Pongoloid"
buttonText:"Swap"
toolTip:"Swap"
(
objpos = #()
objrot = #()
swapper = selection as array
for i = 1 to swapper.count do
(
objpos[i] = swapper[i].pos
objrot[i] = swapper[i].rotation
)
for i = 1 to swapper.count do
(
if i != swapper.count then
(
in coordsys (transmatrix swapper[i].pos) swapper[i].rotation = objrot[(i+1)]
)
else if i >1 do
(
in coordsys (transmatrix swapper[i].pos) swapper[i].rotation = objrot[1]
)
)
for i = 1 to swapper.count do
(
if i != swapper.count then
(
swapper[i].pos = objpos[(i+1)]
)
else if i > 1 do
(
swapper[i].pos = objpos[1]
)
)
)

davestewart
06-06-2007, 09:18 AM
Hey,
How about querying toolmode.CommandMode which will return...


#hierarchy
#select
#move
#rotate
#uscale
#nuscale
#squash


...depending on what transform mode you're in. Not as nice as modifier keys, but still alright, and kinda contect-sensitive.

I usually have my fingers resting on the keyboard shortcuts W, E, R for move, rotate, scale anyway so it would be super quick.

thatoneguy
06-06-2007, 04:31 PM
Good idea! Works perfectly.
macroScript swapper
category:"Pongoloid"
buttonText:"Swap"
toolTip:"Swap"
(
objpos = #()
objrot = #()
swapper = selection as array
for i = 1 to swapper.count do
(
objpos[i] = swapper[i].pos
objrot[i] = swapper[i].rotation
)
if toolmode.CommandMode == #rotate or toolmode.CommandMode == #select then
(
for i = 1 to swapper.count do
(
if i != swapper.count then
(
in coordsys (transmatrix swapper[i].pos) swapper[i].rotation = objrot[(i+1)]
)
else if i >1 do
(
in coordsys (transmatrix swapper[i].pos) swapper[i].rotation = objrot[1]

)
)
)

if toolmode.CommandMode == #move or toolmode.CommandMode == #select then
(
for i = 1 to swapper.count do
(
if i != swapper.count then
(
swapper[i].pos = objpos[(i+1)]
)
else if i > 1 do
(
swapper[i].pos = objpos[1]
)
)
)
)

CGTalk Moderation
06-06-2007, 04:31 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.