PDA

View Full Version : Animation copy script won't work on multiple selection


Mackinder
12-14-2010, 12:49 PM
Hey folks, I'm new to MAXScript and have created a simple bit of code to copy an object's animation and apply it to a new bone, which it is then skinned to.

Here's the code:
gunPart = $
gunBone = bonesys.createbone [0,0,0] [10,0,0] [1,1,1]
gunBone.height=3
gunBone.width=3
gunBone.name = gunPart.name + "Bone"
gunBone.position.controller = copy gunPart.position.controller
deleteKeys gunPart.position.controller
gunSkin=(skin())
addModifier gunPart gunSkin
skinOps.addBone gunPart.modifiers[#Skin] gunBone 1

To to make it work with multiple objects that have been selected I just added this to it:
for i = 1 to selection.count do
(
select selection[i]
gunPart = $
gunBone = bonesys.createbone [0,0,0] [10,0,0] [1,1,1]
gunBone.height=3
gunBone.width=3
gunBone.name = gunPart.name + "Bone"
gunBone.position.controller = copy gunPart.position.controller
deleteKeys gunPart.position.controller
gunSkin=(skin())
addModifier gunPart gunSkin
skinOps.addBone gunPart.modifiers[#Skin] gunBone 1
)

And it just gives me this error:
-- Error occurred in i loop; filename: C:\Work\3dsmax\MAXScript\boneCreatorMulti.ms; position: 57; line: 3
-- Frame:
-- i: 2
-- No ""select"" function for undefined

I don't know what I'm missing here and any help would be greatly appreciated.

lo
12-14-2010, 01:27 PM
the first time you enter the i loop, you are changing the selection to the first object selected.

So when it's time to enter the loop again, i is 2, and it is trying to access selection[2], which does not exist anymore, because the selection count is only 1.

do this instead:


theSel = selection as array
for i = 1 to theSel.count do
(
select theSel[i]
gunPart = $
gunBone = bonesys.createbone [0,0,0] [10,0,0] [1,1,1]
gunBone.height=3
gunBone.width=3
gunBone.name = gunPart.name + "Bone"
gunBone.position.controller = copy gunPart.position.controller
deleteKeys gunPart.position.controller
gunSkin=(skin())
addModifier gunPart gunSkin
skinOps.addBone gunPart.modifiers[#Skin] gunBone 1
)

Mackinder
12-14-2010, 01:36 PM
Awesome!

I can't believe I didn't see that, so simple.

Thanks man!

CGTalk Moderation
12-14-2010, 01:36 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.