Moving keys from Link Constraint (keys access)

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  03 March 2013
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!!
 
  03 March 2013
no way to get access to these keys??
 
  03 March 2013
Try something like this:


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
 
  03 March 2013
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 )
 
  03 March 2013
Originally Posted by martinez: Try something like this:


 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?
 
  03 March 2013
btw. do know how to sort link_constraint targets by time?
 
  03 March 2013
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.


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
 
  03 March 2013
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.


 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?
 
  03 March 2013
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!


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
 
  03 March 2013
i can sort targets with only one line of code
 
  03 March 2013
Spill it! Is there a hidden sort function?
__________________
Juan Martinez | Blog | Animator
 
  03 March 2013
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.
 
  03 March 2013
$.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
 
  03 March 2013
$.controller.setFrameNo 1 ($.controller.getFrameNo 1)

Ha!

And to be thorough!


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 March 2013 at 07:48 PM.
 
  03 March 2013
i said it's simple
 
Thread Closed share thread



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 03:29 AM.


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