PDA

View Full Version : Inherit Parent Script problem


specxor
04-30-2005, 08:40 AM
Hi, Guys,

I have been following cgtalk for quite a while and feel bad that my first post is asking for help rather than contributing but none the less i have problem with a script i have been working on.

I have been trying very hard and spending a lot of time to get mxs down but this problem has got me stumped. One part of my script simply turns off and on (per axis) the parent inherits, now i have had it about a quarter working (i no that make no sense) so i thought after much hair pulling i would post it here to see what you guys can come up with i sure its something simple as it all looks ok to me.

Right click save as

you can download the script here (http://members.optusnet.com.au/davidrm/tool.ms)

I have commented the parts that i think were the problem(s) are...

Thanks in advance guys

Cheers
Dave

Impus
05-01-2005, 02:11 AM
The first big problem was that you were wiping 'ckboxarray' every time a 'rotAp', 'scaAp' or 'moveAp' button was pressed so you weren't able to check if the boxes were checked or not.

I fixed this however you'd notice that since you weren't collecting the current state of the inheritance bit array it kept wiping all the other inheritance flags. I created a 'getCurrInheritance' function that collects the current inheritance state for a specific set of transforms #(#move, #rotate, #scale) - it's at the top of the script.

Also I noticed that each of the apply buttons contained a lot of code duplication (which is bad) so I've also included a version with a rollout function that will handle all three apply buttons.

So below is the fixed version of your implementation:
function getCurrInheritance inputNode getTranforms:#(#move, #rotate, #scale) =
(
local allInheritance = (getInheritanceFlags inputNode);
local returnInheritance = #{}
if (findItem getTranforms #move) != 0 then
(
returnInheritance += (allInheritance - #{4..9});
);
if (findItem getTranforms #rotate) != 0 then
(
returnInheritance += (allInheritance - #{1..3, 7..9});
);
if (findItem getTranforms #scale) != 0 then
(
returnInheritance += (allInheritance - #{1..6});
);

return returnInheritance;
);

rollout aniTool "Animation Helper" width:160 height:616



(
groupBox grbx1 "Animation Controls" pos:[8,32] width:144 height:104
button keyAll "Key All" pos:[16,104] width:56 height:24
button delKey "Del Key" pos:[88,104] width:56 height:24
dropDownList axisSel "Orientation" pos:[16,56] width:128 height:40
label lbl1 " Animation Helper" pos:[8,8] width:144 height:16
groupBox grbx2 "Position" pos:[8,144] width:144 height:112
button posX "X" pos:[16,184] width:24 height:24
label lbl2 "Key" pos:[16,168] width:24 height:16
button posY "Y" pos:[48,184] width:24 height:24
button posZ "Z" pos:[80,184] width:24 height:24
button posAll "All" pos:[112,184] width:32 height:24
label lbl3 "Inherit" pos:[16,216] width:40 height:16
checkbox InPosX "X" pos:[16,232] width:32 height:16 checked:true
checkbox InPosY "Y" pos:[48,232] width:32 height:16 checked:true
checkbox InPosZ "Z" pos:[80,232] width:32 height:16 checked:true
checkbox InposAll "All" pos:[112,232] width:32 height:16 checked:true
groupBox grbx3 "Rotation" pos:[8,264] width:144 height:112
button rotX "X" pos:[16,304] width:24 height:24
label lbl6 "Key" pos:[16,288] width:24 height:16
button rotY "Y" pos:[48,304] width:24 height:24
button rotZ "Z" pos:[80,304] width:24 height:24
button rotAll "All" pos:[112,304] width:32 height:24
label lbl7 "Inherit" pos:[16,336] width:40 height:16
checkbox InRotX "X" pos:[16,352] width:32 height:16 checked:true
checkbox InRotY "Y" pos:[48,352] width:32 height:16 checked:true
checkbox InRotZ "Z" pos:[80,352] width:32 height:16 checked:true
checkbox InRotAll "All" pos:[112,352] width:32 height:16 checked:true
groupBox grbx4 "Scale" pos:[8,384] width:144 height:112
label lbl8 "Key" pos:[16,408] width:24 height:16
button scaZ "Z" pos:[16,424] width:24 height:24
button scaAll "All" pos:[112,424] width:32 height:24
label lbl9 "Inherit" pos:[16,456] width:40 height:16
checkbox InScaX "X" pos:[16,472] width:32 height:16 checked:true
checkbox InScaY "Y" pos:[48,472] width:32 height:16 checked:true
checkbox InScaZ "Z" pos:[80,472] width:32 height:16 checked:true
checkbox InScaAll "All" pos:[112,472] width:32 height:16 checked:true
groupBox grbx5 "Set Inherits" pos:[7,504] width:144 height:48
button moveAp "Move" pos:[16,520] width:32 height:24
button rotAp "Rot" pos:[64,520] width:32 height:24
button scaAp "Scale" pos:[112,520] width:32 height:24





on keyAll pressed do

(
max set key all postion rotation and scale
)

on delKey pressed do

(
max set key clear
)

--Position Key Buttons

on posX pressed do

(
max set key all x position
)

on posY pressed do

(
max set key all y position
)

on posZ pressed do

(
max set key all z position
)

on posAlzl pressed do

(
max set key all position
)

--Rotation Key Buttons

on rotX pressed do

(
max set key all x rotation
)

on rotY pressed do

(
max set key all y rotation
)

on rotZ pressed do

(
max set key all z rotation
)

on rotAll pressed do

(
max set key all rotation
)

--Scale Key Buttons

on scaZ pressed do

(
max set key all z scale
)

on scaAll pressed do

(
max set key all scale
)

--Inherit Checkboxes

local ckboxarray = #(InPosX,InPosY,InPosZ,InRotX,InRotY,InRotZ,InScaX,InScaY,InScaZ)


on InPosAll changed thestate do

(
if InPosAll.checked == true then

(for i = 1 to 3 do (ckboxarray[i].checked = true))

else

(for i = 1 to 3 do (ckboxarray[i].checked = false))
)

on InRotAll changed thestate do

(
if InRotAll.checked == true then

(for i = 4 to 6 do (ckboxarray[i].checked = true))

else

(for i = 4 to 6 do (ckboxarray[i].checked = false))

)

on InScaAll changed thestate do

(
if InScaAll.checked == true then

(for i = 7 to 9 do (ckboxarray[i].checked = true))

else

(for i = 7 to 9 do (ckboxarray[i].checked = false))

)

-- Applys Checkbox Settings

on moveAp pressed do

(

local moveInheritance = #{}

for i = 1 to 3 do
(
if ckboxarray[i].checked == true do (moveInheritance += #{i})
)


for x in selection as array do
(
local inheritanceFlags = ((getCurrInheritance x getTranforms:#(#rotate, #scale)) + moveInheritance)
setinheritanceflags x (inheritanceFlags as bitarray)
)
)

on rotAp pressed do

(
local rotateInheritance = #{}

for i = 4 to 6 do
(
if ckboxarray[i].checked == true do (rotateInheritance += #{i})
)


for x in selection as array do
(
local inheritanceFlags = ((getCurrInheritance x getTranforms:#(#move, #scale)) + rotateInheritance)
setinheritanceflags x (inheritanceFlags as bitarray)
)
)

on scaAp pressed do

(
local scaleInheritance = #{}

for i = 7 to 9 do
(
if ckboxarray[i].checked == true do (scaleInheritance += #{i})
)


for x in selection as array do
(
local inheritanceFlags = ((getCurrInheritance x getTranforms:#(#move, #rotate)) + scaleInheritance)
setinheritanceflags x (inheritanceFlags as bitarray)
)

)


)

createDialog aniTool 160 616

And below is with the improved function:

function getCurrInheritance inputNode getTranforms:#(#move, #rotate, #scale) =
(
local allInheritance = (getInheritanceFlags inputNode);
local returnInheritance = #{}
if (findItem getTranforms #move) != 0 then
(
returnInheritance += (allInheritance - #{4..9});
);
if (findItem getTranforms #rotate) != 0 then
(
returnInheritance += (allInheritance - #{1..3, 7..9});
);
if (findItem getTranforms #scale) != 0 then
(
returnInheritance += (allInheritance - #{1..6});
);

return returnInheritance;
);

rollout aniTool "Animation Helper" width:160 height:616



(
groupBox grbx1 "Animation Controls" pos:[8,32] width:144 height:104
button keyAll "Key All" pos:[16,104] width:56 height:24
button delKey "Del Key" pos:[88,104] width:56 height:24
dropDownList axisSel "Orientation" pos:[16,56] width:128 height:40
label lbl1 " Animation Helper" pos:[8,8] width:144 height:16
groupBox grbx2 "Position" pos:[8,144] width:144 height:112
button posX "X" pos:[16,184] width:24 height:24
label lbl2 "Key" pos:[16,168] width:24 height:16
button posY "Y" pos:[48,184] width:24 height:24
button posZ "Z" pos:[80,184] width:24 height:24
button posAll "All" pos:[112,184] width:32 height:24
label lbl3 "Inherit" pos:[16,216] width:40 height:16
checkbox InPosX "X" pos:[16,232] width:32 height:16 checked:true
checkbox InPosY "Y" pos:[48,232] width:32 height:16 checked:true
checkbox InPosZ "Z" pos:[80,232] width:32 height:16 checked:true
checkbox InposAll "All" pos:[112,232] width:32 height:16 checked:true
groupBox grbx3 "Rotation" pos:[8,264] width:144 height:112
button rotX "X" pos:[16,304] width:24 height:24
label lbl6 "Key" pos:[16,288] width:24 height:16
button rotY "Y" pos:[48,304] width:24 height:24
button rotZ "Z" pos:[80,304] width:24 height:24
button rotAll "All" pos:[112,304] width:32 height:24
label lbl7 "Inherit" pos:[16,336] width:40 height:16
checkbox InRotX "X" pos:[16,352] width:32 height:16 checked:true
checkbox InRotY "Y" pos:[48,352] width:32 height:16 checked:true
checkbox InRotZ "Z" pos:[80,352] width:32 height:16 checked:true
checkbox InRotAll "All" pos:[112,352] width:32 height:16 checked:true
groupBox grbx4 "Scale" pos:[8,384] width:144 height:112
label lbl8 "Key" pos:[16,408] width:24 height:16
button scaZ "Z" pos:[16,424] width:24 height:24
button scaAll "All" pos:[112,424] width:32 height:24
label lbl9 "Inherit" pos:[16,456] width:40 height:16
checkbox InScaX "X" pos:[16,472] width:32 height:16 checked:true
checkbox InScaY "Y" pos:[48,472] width:32 height:16 checked:true
checkbox InScaZ "Z" pos:[80,472] width:32 height:16 checked:true
checkbox InScaAll "All" pos:[112,472] width:32 height:16 checked:true
groupBox grbx5 "Set Inherits" pos:[7,504] width:144 height:48
button moveAp "Move" pos:[16,520] width:32 height:24
button rotAp "Rot" pos:[64,520] width:32 height:24
button scaAp "Scale" pos:[112,520] width:32 height:24





on keyAll pressed do

(
max set key all postion rotation and scale
)

on delKey pressed do

(
max set key clear
)

--Position Key Buttons

on posX pressed do

(
max set key all x position
)

on posY pressed do

(
max set key all y position
)

on posZ pressed do

(
max set key all z position
)

on posAlzl pressed do

(
max set key all position
)

--Rotation Key Buttons

on rotX pressed do

(
max set key all x rotation
)

on rotY pressed do

(
max set key all y rotation
)

on rotZ pressed do

(
max set key all z rotation
)

on rotAll pressed do

(
max set key all rotation
)

--Scale Key Buttons

on scaZ pressed do

(
max set key all z scale
)

on scaAll pressed do

(
max set key all scale
)

--Inherit Checkboxes

local ckboxarray = #(InPosX,InPosY,InPosZ,InRotX,InRotY,InRotZ,InScaX,InScaY,InScaZ)


on InPosAll changed thestate do

(
if InPosAll.checked == true then

(for i = 1 to 3 do (ckboxarray[i].checked = true))

else

(for i = 1 to 3 do (ckboxarray[i].checked = false))
)

on InRotAll changed thestate do

(
if InRotAll.checked == true then

(for i = 4 to 6 do (ckboxarray[i].checked = true))

else

(for i = 4 to 6 do (ckboxarray[i].checked = false))

)

on InScaAll changed thestate do

(
if InScaAll.checked == true then

(for i = 7 to 9 do (ckboxarray[i].checked = true))

else

(for i = 7 to 9 do (ckboxarray[i].checked = false))

)

-- Applys Checkbox Settings
function applyInheritance inputType =
(
local loopInts
local collectInheritance
local addInheritance = #{}

if inputType == #move then
(
loopInts = #(1,3);
collectInheritance = #(#rotate, #scale);
);
if inputType == #rotate then
(
loopInts = #(4,6);
collectInheritance = #(#move, #scale);
);
if inputType == #scale then
(
loopInts = #(7,9);
collectInheritance = #(#move, #rotate);
);



for i = loopInts[1] to loopInts[2] do
(
if ckboxarray[i].checked == true do (addInheritance += #{i})
)

for x in selection as array do
(
local inheritanceFlags = ((getCurrInheritance x getTranforms:collectInheritance) + addInheritance)
setinheritanceflags x (inheritanceFlags as bitarray)
)

);

on moveAp pressed do applyInheritance #move;

on rotAp pressed do applyInheritance #rotate;

on scaAp pressed do applyInheritance #scale;


)

createDialog aniTool 160 616

As I side note I see your from Australia, where abouts are you?

specxor
05-01-2005, 02:40 AM
wow thanks, and i thought it would be a simple fix! well you never no.... So much more to learn... and im from good ol Sydney

Cheers

and thanks heaps again..

CGTalk Moderation
05-01-2005, 02:40 AM
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.