Notifications
Clear all

[Closed] Max Script, thou art so Heartless

Hey everyone, I have been a bit of a lurker on CG society so apologese if no one knows me.

As part of a university assignment I am rigging the old school ariel hunter killer seen in terminator 1 and 2.

From a rigging perspective this isnt exactly a hard vehicle to rig, simple IK and FK solutions, look at constraints and some particle emitters to make it all fancy.

But what I would like to do is make it more complicated. I have started to learn basic max script, and in conjunction with the reaction manager I would like to develop a flight interface of sorts to control the HK.

My problem at the moment (one of many) is that I cannot update the custom attributes rollout bar I have made without resetting the links that have been created in the reaction manager. Which causes several headaches when I want to try out a new spinner or slider, or piece of script.

Below I have pasted in what script I have currently been able to make.

So far I have got the leg sliders linked with the dummies in the scene that move the IK solvers, what Id like to be able to do is make changes to the script and the rollout without having to relink everything in the reaction manager again.

I have so far managed to create a button that could achieve this but every time I try it, I just get an error.

Any input would be greatly appreciated.

Regards

Chris

ca=attributes HKInterface
(
parameters params rollout:HKbox
(
AllLegs type:#float ui:Leg
RearLeftLeg type:#float ui:Leg1
FrontLeftLeg type:#float ui:Leg2
RearRightLeg type:#float ui:Leg3
FrontRightLeg type:#float ui:Leg4

     Yaw type:#float ui:yaw
     Pitch type:#float ui:Pitch
 )
 rollout HKbox "HK Interface"
 (
     local range=[0,100,0]
     slider Leg "All Legs" width: 150 align:#left
     slider Leg1 "Rear Left Leg" width: 150 align:#left 
     slider Leg2 "Front Left Leg" width: 150 align:#left
     slider Leg3 "Rear Right Leg" width: 150 align:#left
     slider Leg4 "Front Right Leg" width: 150 align:#left
     
     slider Jet "All Jets" width: 150 align:#left 
     slider Jet1 "Left Jet" width: 150 align:#left
     slider Jet2 "Right Jet" width: 150 align:#left

     slider Height "Height" width: 150 align:#left

     spinner yaw "Yaw" range:[0,360,180] align:#center offset:[0,0]
     spinner Pitch "Pitch" range:[0,360,180] align:#center offset:[0,0]
 
     Button Fire "Fire Plasma Gun" width: 150 height: 25

     radiobuttons SL "Search Lights" labels:#("on","off")
     
     
     Button Reload "Reload Rollout" width: 150 height: 25
             
     on Reload pressed do    
     (
         custAttributes.redefine old_def new_def_string -- redefine it
     )
 )

)

custAttributes.add $.modifiers[1] ca

1 Reply

This is how I always go about redefining. Try this instead.

/*
  custAttributes.getDef $.modifiers[1] 1 -- Run this line while selecting the node that you have added the def to.  It will get the def instance and store it back in the variable ca.
  */
  
  ca=attributes HKInterface
  	redefine:ca -- Add this line after the def has been added and the variable ca is storing the def instance.  Just comment it out when initially creating the def.
  (
  parameters params rollout:HKbox
  (
  AllLegs type:#float ui:Leg
  RearLeftLeg type:#float ui:Leg1
  FrontLeftLeg type:#float ui:Leg2
  RearRightLeg type:#float ui:Leg3
  FrontRightLeg type:#float ui:Leg4
  
  Yaw type:#float ui:yaw
  Pitch type:#float ui:Pitch
  )
  rollout HKbox "HK Interface"
  (
  local range=[0,100,0]
  slider Leg "All Legs" width: 150 align:#left
  slider Leg1 "Rear Left Leg" width: 150 align:#left
  slider Leg2 "Front Left Leg" width: 150 align:#left
  slider Leg3 "Rear Right Leg" width: 150 align:#left
  slider Leg4 "Front Right Leg" width: 150 align:#left
  
  slider Jet "All Jets" width: 150 align:#left
  slider Jet1 "Left Jet" width: 150 align:#left
  slider Jet2 "Right Jet" width: 150 align:#left
  
  slider Height "Height" width: 150 align:#left
  
  spinner yaw "Yaw" range:[0,360,180] align:#center offset:[0,0]
  spinner Pitch "Pitch" range:[0,360,180] align:#center offset:[0,0]
  
  Button Fire "Fire Plasma Gun" width: 150 height: 25
  
  radiobuttons SL "Search Lights" labels:#("on","off")
  
  -- Not needed
  -- Button Reload "Reload Rollout" width: 150 height: 25
  
  -- on Reload pressed do
  -- (
  -- custAttributes.redefine old_def new_def_string -- redefine it
  -- )
  )
  )
  
  /*
  -- Only evaluate this line when adding the def to an object, not when redefining an existing def.  Commented out, for this reason.
  custAttributes.add $.modifiers[1] ca
  */

That should keep your controllers and everything in tact, as long as you leave the parameter names the same. If you need to change the parameter names, look into remapping.

I’ve left some comments throughout the code. Read them to know what is going on. Hope this helps and is what you’re looking for.