Notifications
Clear all

[Closed] Animating Linked Objects

Hello again,
I’m currently using a checkbutton that links an object(which will be selected with pickbutton…eventually) to a hand. So far i have the script working correctly but my only concern is that when i unlink the object, it does not store any keyframes related to the movement of the hand.
How exactly can I get the child object to inherit the keyframes from the parent object? Can anyone suggest another way of doing this?

checkbutton ckbLinktoHand "" pos:[608, 223] width:128 height:38 
       
       on ckblinktohand changed state do
       	 if state==true then
       	   $object01.parent=$hand01
       	 else
       	   $object01.parent=undefined
       
7 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

The best way of doing such things is to use link constraint. Link constraint allows you inherit keys, animate both parent and child, and keep the animation history for a tweaking.

Here is a sample that illustrates how it works (run it in an empty scene):


prop = Sphere radius:20 smooth:on segs:32 transform:(matrix3 [1,0,0] [0,0,1] [0,-1,0] [-140,0,0]) name:"Prop" wirecolor:blue
prop.transform.controller = Link_Constraint key_mode:2 key_hierarchy_mode:0 -- inherit keys for children
hand1 = Box length:30 width:30 height:30 transform:(matrix3 [1,0,0] [0,0,1] [0,-1,0] [20,0,40]) name:"Hand1" wirecolor:brown
hand2 = Box length:30 width:30 height:30 transform:(matrix3 [1,0,0] [0,0,1] [0,-1,0] [120,0,-30]) name:"Hand2" wirecolor:orange
with animate on 
(
 prop.transform.controller.addWorld frameNo:0 
 at time 0 tm = prop.transform = prop.transform
 at time 25 
 (
  move prop [170,0,90]
  hand1.transform = hand1.transform
 )
 prop.transform.controller.addTarget hand1 25
 at time 50
 (
  move hand1 [140,-25,0]
  rotate hand1 (EulerAngles 0 150 0)
  hand2.transform = hand2.transform
 )
 prop.transform.controller.key_hierarchy_mode = 0
 prop.transform.controller.addTarget hand2 50
 at time 70
 (
  move hand2 [-130,0,0]
  hand2.transform = hand2.transform
 )
 at time 90 rotate hand2 (EulerAngles 0 -120 0)
 prop.transform.controller.key_hierarchy_mode = 0
 prop.transform.controller.addWorld frameNo:80
 at time 100 prop.transform = tm
)
slidertime = 0

To clarify, you link object “hand” to object “arm”. You animate the arm and then unlink the hand and want the keys from the arm to be applied to the hand? As far as I know max doesn’t have this functionality built in. You have to step through the keys on the arm and apply them to hand via maxScript (I could be wrong on this one, though).

Using link constraint was my backup plan, but I was hoping to create a more adaptable system that would work with any object, regardless of whether it has a link constraint or not, but unfortunately after experimenting a bit more it seems like an impossible option in this case.
What I may end up doing is getting the script to apply the link constraint to whatever object is picked up and reading the frame value from the timeline as soon as the link button is enabled/disabled, to set the link constraint’s start/end frames.
I will keep this updated when i resolve it.
Thanks for the suggestions so far.

I’m starting to make progress with this and I decided to store the chosen linked objects in a drop down menu. So far so good, but now I need to store the array in an ini which is where i’m having problems.

My first issue is appending within the ini. It appends to the array without problems within max but if i open the ini after closing the window, it seems to overwrite.(look below at my ini code)

My second problem is loading it back in, no matter how it saves, whether it’s one object with proper array format or not, it comes out as #(“Cylinder180”) for example rather than just Cylinder180in the dropdown menu.

macroScript TEST
 category:"My Tools"
 
 
 (
 rollout window "TAB3" width:200 height:100
 
 (
 
 
 local num1=#()
 
 local ininum=#((getINISetting "d:/test/3dstest.ini" "values" "Array") as string)
 
  dropdownlist ddlLinkSelectList "Scale" items:ininum
 	pickbutton pkbLinkSelect "Select Object" pos:[10, 70] width:80 height:15
 
 on pkbLinkSelect picked obj do
 	if isValidNode obj then ddlLinkSelectlist.items = append ininum obj.name
 on window close do
 	setINISetting "d:/test/3dstest.ini" "values" "Array" (ininum as string)
 )
 createDialog window width:200 height:100
 
 )

My ini code

[values]
 
 Array=#("#("#("#()", "Cylinder180", "Cylinder185")", "Cylinder181", "Box39")")

It was hard to find proper information or examples for this online and any progress I have made with this, is by using maxscript help. I’m here as a last resort, any help is really appreciated.


fn setINI nodes:[i]<your_nodes_array>[/i] =  
(
 str = stringStream ""
 for n in nodes do format "$'%'|" n.name to:str
 setINISetting [i]<your_ini_file> <name>[/i] (str as string)
)
fn getINI =
(
 str = getINISetting [i]<your_ini_file> <name>
[/i] str = filterString str "|"
 nodes = for s in str where iskindof (n = execute s) Node collect n
)

here is it

Thanks again Dennis, but unfortunately I lacked the knowledge to implement that code and could not get it working properly.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

what’s wrong? what is not working?