CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »
 
Thread Tools Search this Thread Display Modes
Old 03-24-2013, 12:01 PM   #1
esteban73
Veteran
portfolio
Esteban Böhm
Hamburg, Germany
 
Join Date: Dec 2006
Posts: 62
Moving keys from Link Constraint (keys access)

Hi,

I canīt get to move the keys from an object with Link Constraint.
I want to do this: I have an object A whitch have to go through many assembly lines. This object A has sometimes his own keys and sometimes follows another object with Link-Constraint.
I have the whole animation done and now I have to multiply this object A many times, but they have to start i.e. 40 frames later from the front one.

I want to do this with maxscript.
With this simple script I can multiply object A and move the keys 40 frames later (sure not the best script)
HTML Code:
A = $Box001 fr = 0 for i = 1 to 100 do ( i = instance A moveKeys i (fr + 40) fr = fr + 40 )


..., but I cant move the keyframes from the Link-Constraint, only the own keys (rot/pos/scale) are moving...

I saw another thread where there were talking about getframeno, getnumyargets, deletetarget but I dont understand it and I think that's not the solution for my problem.

is it possible?
Thanks!!
 
Old 03-27-2013, 06:15 AM   #2
esteban73
Veteran
portfolio
Esteban Böhm
Hamburg, Germany
 
Join Date: Dec 2006
Posts: 62
no way to get access to these keys??
 
Old 03-27-2013, 12:55 PM   #3
martinez
Expert
 
martinez's Avatar
portfolio
Juan Martinez
Animator
Verse, Inc
Dallas, USA
 
Join Date: Feb 2002
Posts: 206
Send a message via ICQ to martinez Send a message via AIM to martinez
Try something like this:

Code:
for obj in selection do ( nTargets = obj.controller.getNumTargets() for i = nTargets to 1 by -1 do ( fNumber = obj.controller.getFrameNo i obj.controller.setFrameNo i (fNumber + 40) ) )
__________________
Juan Martinez | Blog | Animator
 
Old 03-27-2013, 01:35 PM   #4
esteban73
Veteran
portfolio
Esteban Böhm
Hamburg, Germany
 
Join Date: Dec 2006
Posts: 62
thanks Martinez!
It wokrs perfectly!

here the final script:

HTML Code:
A = $MASTER fr = 0 for i = 1 to 200 do ( obj = instance A nTargets = obj.controller.getNumTargets() for i = nTargets to 1 by -1 do ( fNumber = obj.controller.getFrameNo i obj.controller.setFrameNo i (fNumber +(fr + 40)) ) moveKeys obj (fr + 40) fr = fr + 40 )
 
Old 03-27-2013, 01:59 PM   #5
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,318
Send a message via ICQ to denisT
Quote:
Originally Posted by martinez
Try something like this:

Code:
for obj in selection do ( nTargets = obj.controller.getNumTargets() for i = nTargets to 1 by -1 do ( fNumber = obj.controller.getFrameNo i obj.controller.setFrameNo i (fNumber + 40) ) )

could you write universal function to move link_constrain keys?
 
Old 03-27-2013, 03:05 PM   #6
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,318
Send a message via ICQ to denisT
btw. do know how to sort link_constraint targets by time?
 
Old 03-27-2013, 07:02 PM   #7
martinez
Expert
 
martinez's Avatar
portfolio
Juan Martinez
Animator
Verse, Inc
Dallas, USA
 
Join Date: Feb 2002
Posts: 206
Send a message via ICQ to martinez Send a message via AIM to martinez
Quote:
Originally Posted by denisT
could you write universal function to move link_constrain keys?


I'm only trying, because I think I'll learn something!

My problem with this function is that moveKeys is already a mapped function, so it doesn't need to be IN another mapped function.

Code:
mapped fn moveKeysAndLinkConstraint obj offset = ( moveKeys obj offset if classof obj.controller == Link_Constraint do ( nTargets = obj.controller.getNumTargets() for i = nTargets to 1 by -1 do ( fNumber = obj.controller.getFrameNo i obj.controller.setFrameNo i (fNumber + offset) ) ) ) moveKeysAndLinkConstraint selection 5
__________________
Juan Martinez | Blog | Animator
 
Old 03-27-2013, 07:19 PM   #8
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,318
Send a message via ICQ to denisT
Quote:
Originally Posted by martinez
I'm only trying, because I think I'll learn something!

My problem with this function is that moveKeys is already a mapped function, so it doesn't need to be IN another mapped function.

Code:
mapped fn moveKeysAndLinkConstraint obj offset = ( moveKeys obj offset if classof obj.controller == Link_Constraint do ( nTargets = obj.controller.getNumTargets() for i = nTargets to 1 by -1 do ( fNumber = obj.controller.getFrameNo i obj.controller.setFrameNo i (fNumber + offset) ) ) ) moveKeysAndLinkConstraint selection 5

there are two another problems...
#1 what is if the offset is negative?
#2 what is if the targets are not sorted?
 
Old 03-28-2013, 04:16 PM   #9
martinez
Expert
 
martinez's Avatar
portfolio
Juan Martinez
Animator
Verse, Inc
Dallas, USA
 
Join Date: Feb 2002
Posts: 206
Send a message via ICQ to martinez Send a message via AIM to martinez
Quote:
Originally Posted by denisT
there are two another problems...
#1 what is if the offset is negative?
#2 what is if the targets are not sorted?


#1 Added a check to see if the offset is positive or negative. Moving a key on top of each other in the time slider results in the target key being removed. But moving a key on top of another with MaxScript result in the key being "bumped" over to the previous frame. (Similar to using the interface.)

#2 I found no built in method to sort the targets before starting. If a user types in a frame number in the target list it becomes unsorted. Using the arrows of the spinner will sort the targets, but no script methods sort the targets. I used a simple sort function to sort the array. But my method fails if the same object is used more than once.

This should be simple!

Code:
EscapeEnable = true clearlistener() --BUBBLE SORT THE FRAMES AND NODES fn SortByFrames TargetArray IndexArray = ( SortingArray = #() tCount = TargetArray.count while TargetArray as string != SortingArray as string do ( SortingArray = deepCopy TargetArray for i = 1 to tCount-1 do ( if IndexArray[i] > IndexArray[i+1] do ( swap IndexArray[i] IndexArray[i+1] swap TargetArray[i] TargetArray[i+1] ) ) ) return #(TargetArray,IndexArray) ) mapped fn moveKeysAndLinkConstraint obj offset = ( moveKeys obj offset if classof obj.controller == Link_Constraint do ( nTargets = obj.controller.getNumTargets() NodeArray = for i = 1 to nTargets collect obj.controller.getNode i FrameArray = for i = 1 to nTargets collect obj.controller.getFrameNo i ResultsArray = SortByFrames NodeArray FrameArray if offset > 0 then ( for i = nTargets to 1 by -1 do ( l = findItem NodeArray ResultsArray[1][i] obj.controller.setFrameNo l (FrameArray[l] + offset) ) ) else ( for i = 1 to nTargets do ( l = findItem NodeArray ResultsArray[1][i] obj.controller.setFrameNo l (FrameArray[l] + offset) ) ) ) ) moveKeysAndLinkConstraint selection -5
__________________
Juan Martinez | Blog | Animator
 
Old 03-28-2013, 04:35 PM   #10
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,318
Send a message via ICQ to denisT
i can sort targets with only one line of code
 
Old 03-28-2013, 05:58 PM   #11
martinez
Expert
 
martinez's Avatar
portfolio
Juan Martinez
Animator
Verse, Inc
Dallas, USA
 
Join Date: Feb 2002
Posts: 206
Send a message via ICQ to martinez Send a message via AIM to martinez
Spill it! Is there a hidden sort function?
__________________
Juan Martinez | Blog | Animator
 
Old 03-28-2013, 06:11 PM   #12
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,318
Send a message via ICQ to denisT
Quote:
Originally Posted by martinez
Spill it! Is there a hidden sort function?

no... everything is visible try to guess. when i show you will see how simple it is.
 
Old 03-28-2013, 07:42 PM   #13
martinez
Expert
 
martinez's Avatar
portfolio
Juan Martinez
Animator
Verse, Inc
Dallas, USA
 
Join Date: Feb 2002
Posts: 206
Send a message via ICQ to martinez Send a message via AIM to martinez
$.controller.addWorld frameNo:-9999
$.controller.DeleteTarget 1

This will sort the list, but it's not one line of code. Actually, just the first line will sort it, but then I need to remove it.
__________________
Juan Martinez | Blog | Animator
 
Old 03-28-2013, 07:43 PM   #14
martinez
Expert
 
martinez's Avatar
portfolio
Juan Martinez
Animator
Verse, Inc
Dallas, USA
 
Join Date: Feb 2002
Posts: 206
Send a message via ICQ to martinez Send a message via AIM to martinez
$.controller.setFrameNo 1 ($.controller.getFrameNo 1)

Ha!

And to be thorough!

Code:
mapped fn moveKeysAndLinkConstraint obj offset = ( moveKeys obj offset if classof obj.controller == Link_Constraint do ( nTargets = obj.controller.getNumTargets() if nTargets > 0 do ( --SORT THE LINK CONSTRAINT TARGETS obj.controller.setFrameNo 1 (obj.controller.getFrameNo 1) if offset > 0 then ( for i = nTargets to 1 by -1 do ( fNumber = obj.controller.getFrameNo i obj.controller.setFrameNo i (fNumber + offset) ) ) else ( for i = 1 to nTargets do ( fNumber = obj.controller.getFrameNo i obj.controller.setFrameNo i (fNumber + offset) ) ) ) ) ) moveKeysAndLinkConstraint selection 5
__________________
Juan Martinez | Blog | Animator

Last edited by martinez : 03-28-2013 at 07:48 PM.
 
Old 03-28-2013, 08:56 PM   #15
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,318
Send a message via ICQ to denisT
i said it's simple
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright Đ2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 06:06 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.