Sort camera's keys selection range on timeline

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
  05 May 2008
Sort camera's keys selection range on timeline

Hi Guys,
I am new in maxscript and last couple of days I tried to write this script. It should select all cameras in scene and sort their "animationkeys" selection range on timeline. It does not work properly, the result should move the first key of the camera (including cam.target's keys) animation range right behind the previous camera last key and continue this way with next cameras. Sometimes I get small overlaps or holes between selection ranges of neighboring cameras.

here is the code:
Quote: --array of cameras

select $cam*
deselect $*target
cams = selection as array
Cnames = for i in selection collect i.name
sort Cnames
cams = for i in Cnames collect getNodeByName i

--array of camera.targets

select $*target
deselect lights
targs = selection as array
Tnames = for i in selection collect i.name
sort Tnames
targs = for i in Tnames collect getNodeByName i

--move camera's to zero

for i = 1 to cams.count do
(
for j = i to i do
(
C = (getkeytime cams[i].pos.controller 1)
T = (getkeytime targs[j].pos.controller 1)
if C <= T then movekeys cams[i] -C else movekeys cams[i] -T
if C <= T then movekeys targs[i] -C else movekeys targs[i] -T
)
)

--sort cameras in time

values = #()
for i = 1 to cams.count do
(
for j = i to i do
(
C = (getkeytime cams[i].pos.controller (numkeys cams[i].pos.controller))
T = (getkeytime targs[j].pos.controller (numkeys targs[j].pos.controller))
if C >= T then append values C else append values T
sum = 0
(
for i=1 to values.count do
(
sum = sum + values[i]
)
)
sum
movekeys cams[i] sum
movekeys targs[j] sum
)
)
movekeys cameras -values[1]
deselect cameras


could anybody help me please?
Thanks
Filip
__________________
sorry for my english....
 
  05 May 2008
Hi Filip,
Sorry - I don't understand your question! Could you post a screenshot or something?
Thanks,
Dave
__________________
Portfolio | Keyframes and Code
 
  05 May 2008
Hi Dave, thanks for reply!
here is, I hope, better description:
__________________
sorry for my english....
 
  05 May 2008
Here's a script that (I think) does what you want. There's no error checking whatsoever, it assumes the position controllers of both the camera and its target contain keys.

(
	-- function to sort cameras by name
	fn sortByName a b = stricmp a.name b.name
	
	-- collect target cameras
	local cams = for obj in cameras where classOf obj == Targetcamera collect obj
	-- sort camera array by name
	qSort cams sortByName
	
	-- initial time
	local curtime = 0f
	
	with undo "Sort cams" on
	(
		-- iterate through cameras
		for i = 1 to cams.count do
		(
			-- get camera+target position controllers
			camctrl = cams[i].position.controller
			trgctrl = cams[i].target.position.controller
			-- get camera animation range
			camtime_first = amin camctrl.keys[1].time trgctrl.keys[1].time
			camtime_last = amax camctrl.keys[camctrl.keys.count].time trgctrl.keys[trgctrl.keys.count].time
			camtime_length = camtime_last - camtime_first
			-- number of frames to shift
			movetime = -camtime_first + curtime
			-- move keys for both the camera and its target
			moveKeys camctrl movetime
			moveKeys trgctrl movetime
			-- first key time for next camera
			curtime += camtime_length + 1
		)
	)
)

Hope this helps, if you have any questions regarding this script don't hesitate to ask.

Martijn
 
  05 May 2008
Martijn,

It works great, exactly what I wanted
I've spent hard time with my own and it does not work well,
have to learn from your code!

I really appreciate it
Filip
__________________
sorry for my english....
 
  05 May 2008
I was tidying up an old camera script the other day, and it occurred to me halfway through that the thing to remember with cameras is that it's only really the target property (on target cameras only) that makes them so different from normal objects.

With this in mind, for anything that will affect a camera, it's worth putting any code that will affect the target in a conditional statement, and that way you build yourself a tool that isn't exclusive to cameras.

Therefore you could have a rather nice (and general) "butt up all animation" tool at your disposal, that you could run on any objects.

Also, movekeys works on any child tracks as well, so you could affect the whole transform (rotations, etc).

Just a thought or two
__________________
Portfolio | Keyframes and Code
 
  06 June 2008
Martijn,

I like your script, its elegant way (at least for me - beginner).
Could you explain me please this part of your code?

with undo "Sort cams" on

what does this exactly do?

Many Thanks
Filip
__________________
sorry for my english....
 
  06 June 2008
Originally Posted by filanek: Could you explain me please this part of your code?

with undo "Sort cams" on

what does this exactly do?


This line tells max to create an undo entry for the following codeblock.

If you run the following line:
with undo off box()
you'll notice that there's no undo entry added to the history.

with undo on
(
b = box()
addModifier b (uvwmap())
)


This creates a single undo entry for both actions. If you look up 'undo' in the reference, you'll see that you can also specify a label for the undo entry that is being created. This does not work in all situations though (it will appear as "MAXScript" instead of the specified label), I'm not sure when or why this happens.

Martijn
 
  06 June 2008
Thanks Martijn, clear enough!
cheers
Filip
__________________
sorry for my english....
 
  06 June 2008
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
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 05:04 PM.


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