ScriptSpot

Forum topic · Scripts Wanted

Create key frames and rotate selected object

By kenosis · 2013-09-15

Description

Hello there!

I was doing some 2d game creation and rendering models in 8 directions. Each move should be rendered 8 times. Adjusting the scene by hand is too time-consuming. A script that sets the scene should be very helpful.

The script should work like this:

First I input a number X, how many frames each move has.
Select clockwise or anticlockwise
Create key frame at 1
create key frame at X
create key frame at X+1, rotate selected object by 0,0,45 or 0,0,-45
create key frame at 2X
create key frame at 2X+1, rotate selected object by 0,0,45 or 0,0,-45
...................
Create key frame at 7X+1, rotate selected object by 0,0,45 or 0,0,-45

Thank you!

Comments (7)

kenosis · 2013-09-15

Sorry, my max2012 says "count" undefined
at these lines

rendPickupFrames = (str = "0," ; for i = 1 to a.count while i != a.count do str+= (a[i] as string + ",") ; str += a[a.count] as string ; str)
if rendTimeType != 4 do rendTimeType = 4

I was using solution #1

barigazy · 2013-09-15

Yup. I already fix that. Copy code again or replace "a" with "arr"

kenosis · 2013-09-15

Thank you man!

barigazy · 2013-09-15

Wait a bit I have better solution.

barigazy · 2013-09-15

Look at this solution. Also read comments because there is two examples.
Test this separately
fn zRotKeys obj rotType:#cw xTime: step: ang: =
(
maxops.getDefaultTangentType &iT &oT
maxops.setDefaultTangentType #step #step
local mode = if isKindOf ang Array then #multyAngles else #singleAngle
step = if mode==#multyAngles then ang.count else step
local arr = for i = 1 to step collect i*xTime
for i = 1 to arr.count do
(
with animate on at time arr[i]
(
if rotType == #ccw then (obj[3][2][3].track.value += (if mode == #singleAngle then ang else ang[i]))
else obj[3][2][3].track.value -= (if mode == #singleAngle then ang else ang[i])
)
)
maxops.setDefaultTangentType iT oT
rendPickupFrames = (str = "0," ; for i = 1 to arr.count while i != arr.count do str+= (arr[i] as string + ",") ; str += arr[arr.count] as string ; str)
if rendTimeType != 4 do rendTimeType = 4
renderSceneDialog.update()
)
-- this function will be also set your renderer to consider only used keys for rendering
-- open Render Setup Dialog > CommonTab >Common Parameters Rollout > Time Output > FRAMES

-- example #1
-- "rotType argument can be #cw or #ccw"
tea = Teapot isSelected:on
zRotKeys tea rotType:#cw xTime:10 step:7 ang:45

-- example #2
-- U can use array of custom defined angles
-- In this case leave "step" argument as 1 because array count will be used
tk = Torus_Knot radius:10 radius2:3 isSelected:on
zRotKeys tk rotType:#cw xTime:10 step:1 ang:#(50,135,-30,270,68,45,-180,75,90)

barigazy · 2013-09-15

Something like this

fn zRotKeys obj rotType:#cw x: step: ang: =
(
local arr = #()
for i = 1 to step do
(
for j = 1 to 2 do append arr (if mod j 2 != 0 then i*x else (i*x+(j-1)))
)
addNewKey obj[3][2][3].track 1
for i = 1 to arr.count do
(
if mod i 2 != 0 then (addNewKey obj[3][2][3].track arr[i]) else
(
with animate on at time arr[i]
(
if rotType == #ccw then obj[3][2][3].track.value += ang else obj[3][2][3].track.value -= ang
)
)
)
)
-- example
-- "rotType argument can be #cw or #ccw"
tea = Teapot()
zRotKeys tea rotType:#cw x:10 step:7 ang:45