PDA

View Full Version : Max Rigging the number of frames to a Custom Attribute


dande
02-06-2011, 11:01 PM
I have a general rigging question. I have a number of rigged objects connected to a path constraint. I need to change the speed of these objects from time to time. I can easily do this by setting the number of frames in the track bar. This is time consuming. I would like to be able to set the frame length of these objects through a custom attribute. How can I access the number of frames through rigging

Thanks

Pacermike
02-11-2011, 09:24 PM
Hey, not sure if this is what you meant but here's some Custom Attributes will make a spinner that can move the end key frame of an object animated along a path constraint. The way it's written right now would only work on an object named box02 and would only move the second frame on a path constrained object. You could change the script to do whatever you wanted it to though. I attached a max file (made in Max 9. Ignore the "missing DLLs" error that pops up, its just a bunch of work plugins). Just select the box and slide the spinner in the End Frame rollout under Box02's Modify tab.

frameCA =
attributes Frame_Mover
(
parameters main rollout:spinnersRol
(
spinOne type:#integer ui:spn_one
)

rollout spinnersRol "End Frame"
(
spinner spn_one type:#integer

fn fart here =
(
moveKey $box02.controller[1][2][1].controller 2 ((here.frame)-(getKeyTime $box02.controller[1][2][1].controller 2))
)

on spn_one changed val do fart ((normTime val)/100)
)
)

Hope this helps.

dande
02-12-2011, 11:27 AM
Thanks.

Thats exactly what I'm looking for. I can change the code to suit my object. But where do I put the code?

dande
02-13-2011, 05:07 PM
Thanks. Thats exactly what I'm looking for. I can change the code to suit the objects in my scene. But where should I put the code?

Thanks again for your help

Pacermike
02-13-2011, 07:28 PM
You just add the code to the actual object. In the test scene file the object was Box02. So in the Listener or in a new script window evaluate the first code I gave you which gives "frameCA" a definition.

Then evaluate this in the Listener:

custAttributes.add $Box02 frameCA
This will add "frameCA" to the Box02 example object. Once the attribute definition is on the object you can redefine it to make changes to the code like this:

-- frameCA = /I comment out the first line so it doesn't evaluate/
attributes Frame_Mover
redefine:frameCA -- /This line tells it to redefine the definition/
(
-- /Then make whatever changes to the body of the code../
)
When you start really getting in to this go to the Maxscript Reference under the Help menu and look up "Custom Attribute". Read all the help files a few times and eventually it'll start making sense.

dande
02-13-2011, 07:59 PM
Thanks again for you help. I really appreciate it.

dande
02-14-2011, 12:26 PM
I have created a scene similar to yours. Added a path constraint to the box. Then added the code as you described. But when I set the number of frames I get the following error

-- Error occurred in fart()
-- Frame:
-- here: 1000f
-- called in spn_one.changed()
-- Frame:
-- val: 100
>> MAXScript Rollout Handler Exception: -- Unknown property: "controller" in undefined <<

I've been playing about with it and I can't fix it.

Thanks

Pacermike
02-14-2011, 06:41 PM
Hehe, "Error occurred in fart()". :p

My guess is it has something to do with "$box02.controller[1][2][1].controller". Controller[1][2][1].controller is looking for the first controller "[1]" which is a Position List. Nested in that Position List is "[2]", the Path Constraint. Within the Path Constraint are four float values and the first one, "[1]" is the Percent Float. The controller on the Percent Float holds the animated Key property that we're trying to access and manipulate through the script. So we get, $box02.controller[1][2][1].controller. This is a very specific way of accessing the key on an object so if anything is out of order the script won't know what's it's looking for and will come back as undefined.

You want to save the file as an archive (.zip) and attach it? I can take a look and see if I can tell what's breaking it.

Also, try this:

frameCA =
attributes Frame_Mover
(
parameters main rollout:spinnersRol
(
spinOne type:#integer ui:spn_one
)

rollout spinnersRol "End Frame"
(
spinner spn_one type:#integer range: [1, ((animationRange.end).frame), 0]

fn fart here =
(
local zoot = exprForMAXObject (custAttributes.getOwner this) explicitNames:true
local toot = execute zoot

moveKey toot.controller[1][2][1].controller 2 ((here.frame)-(getKeyTime toot.controller[1][2][1].controller 2))
)

on spn_one changed val do fart ((normTime val)/(abs animationRange.start + abs animationRange.end).frame)
)
)

I changed it so that the spinner will adjust to the length of the animation timeline. I also changed it so that the name of the object doesn't matter anymore. "exprForMAXObject (custAttributes.getOwner this) explicitNames:true" finds the name of the object that has the Custom Attribute on it, so if a name mismatch was causing your crash before this should fix that. Let me know if it works out.

dande
02-17-2011, 03:25 PM
Thanks for your help I got it working. The error problem was that even if I changed the name of the object to Box01 in the code and ran the code the controller error was being caused by Max looking for your box02. So reading through your information I changed the code to the following and it now works really well

"frameCA = attributes Frame_Mover
(
parameters main rollout:spinnersRol
(
spinOne type:#integer ui:spn_one
)

rollout spinnersRol "Animation"
(
spinner spn_one type:#integer range: [1, ((animationRange.end).frame), 0]

fn fart here =
(
moveKey $box01.controller[1][2][1].controller 2 ((here.frame)-(getKeyTime $box01.controller[1][2][1].controller 2))
)

on spn_one changed val do fart ((normTime val)/100)
)
)

custAttributes.add $box01 frameCA"

Pacermike
02-17-2011, 06:26 PM
Cool, man. Glad to hear it! :)

CGTalk Moderation
02-17-2011, 06:26 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.