[Closed] prob with loop assigned controllers instancing
Heya Folks,
I’m working on a script to assign an array of controllers to an object by assigning the first controller in the array, then assigning a list controller, then finally running through the entries from 2 on in the array and assigning each to the available slots of the list controller
My problem is that if I do the loop as described above the controllers become instanced and the objects pop to a new position unexpectedly. If however I skip assigning the first array controller and directly put on the list controller it doesn’t cause this problem.
Has anyone seen this before or know of the syntax to make each controller unique?
Here’s a script that will make three bones, store them in an array and apply the function to them – it’s set to work properly at the moment by not assigning the first controller, you’ll see the three lines commented that cause my problem.
-- Make an array for our bones to feed into the freezetrans function
Bonearray = #()
b1 = bonesys.createbone [0,0,0] [50,0,0] [0,0,1]
append BoneArray b1
b2 = bonesys.createbone [50,0,0] [100,0,0] [0,0,1]
append BoneArray b2
b3 = bonesys.createbone [100,0,0] [150,0,0] [0,0,1]
append BoneArray b3
b2.parent = b1
b3.parent = b2
-- function name, object to apple the fn to, array of position controllers, array of rotation controllers, position controller to set active, rotation controller to set active
fn FreezeTrans obj ThePosContArray TheRotContArray ActivePosCont ActiveRotCont =
(
-- Set Up position lists - This works fine by keeping the objects original pos controller
obj.position.controller = position_list()
obj.position.controller.setname 1 ThePosContArray[1][2] as string
-- However, if I assign the first controller of the PosArray it instances all
-- other controllers from then on and makes the bones pop. Comment the above two lines and uncomment the three under
-- Commented to stop bones popping to another position
/*
obj.position.controller = ThePosContArray[1][1] -- Sets the default controller as the first cont in the array
obj.position.controller = position_list() -- Then assigns our list controller
obj.position.controller.setname 1 ThePosContArray[1][2] as string -- Names the first entry in the list controller
*/
-- Loop through other positions and assign controllers based on posarray count
if ThePosContArray.count > 1 then
(
for p = 2 to ThePosContArray.count do
(
obj.position.controller.available.controller = ThePosContArray[p][1]
obj.position.controller.setname p ThePosContArray[p][2] as string
)
)
obj.position.controller.SetActive ActivePosCont
-- do the same job with the rotations - I havent included the problems above as they're the same with rotations too
obj.rotation.controller = Rotation_list()
obj.rotation.controller.setname 1 TheRotContArray[1][2] as string
if TheRotContArray.count > 1 then
(
for r = 2 to TheRotContArray.count do
(
obj.rotation.controller.available.controller = TheRotContArray[r][1]
obj.rotation.controller.setname r TheRotContArray[r][2] as string
)
)
obj.Rotation.controller.SetActive ActiveRotCont
)
-- make an array with controller types and names to assign
TempPosArray = #(#(position_xyz(),"Frozen_Position"),#(position_xyz(),"Zero_Position"))
TempRotArray = #(#(Euler_xyz(),"Frozen_Rotation"),#(Euler_xyz(),"Splay_Rotation"),#(Euler_xyz(),"Linked_rotation"),#(Euler_xyz(),"Zero_rotation"))
for i = 1 to bonearray.count do
(
FreezeTrans bonearray[i] TempPosArray TempRotArray 2 4
)
Any ideas how to solve this?
Thanks again,
John
Oh and another thing,
If I don’t use the loop method it seems to work fine (effectively this becomes fred ruffs freeze transform macro) but I’d like to have a more flexible function that can deal with any number of controllers.
Cheers,
John
hey john,
i havent talked to you for a while im busy making my website i have only glanced at it – ill get back to you in a few mins when i can check the script , im rendering at the moment
i would say the best way to deal with looping throught the lists is with a recursive function
i used it on a script i wrote that turns off all keyable attributes on objects even if they contain multiple nested list controlers
mark
hi john,
had a better look at it now –
it seems you are setting the pos list to all bones at once
Yeah I’m wondering if there’s any way to do this during the loop rather than having to do something with getsubanims afterwards. The curious thing is why does it work if I skip the first entry in the loop? If I assign then first controller, then the list I get the problems. If I assign the list, then the first controller I get the same problem? The only way it works is to not bother with the first controller, assign the list directly and loop through from controller two onwards.
The Freeze transform script from fred ruff assigns two controllers manually whereas mine assigns the first one manually and loops from the second on which causes the problem. I’m fairly confused as to why this may be…
Hows the animation coming on?
im kindof confused as to what you are trying to achieve here – maybe i just dont get it or its overcomplicated –
what exactly do you want the script to do?
mark
Effectively a more flexible freeze transforms that drives its loops based on the count of the controllers in an array, rather than typing out the controller assignments by hand. It’s pretty much a mass assigner for list controllers.
after reading it again you are actually applying instances of controller
look at the array
TempPosArray = #(#(position_xyz(),“Frozen_Position”),#(position_xyz(),“Zero_Position”))
eveytime you assing the element tempposarray(ThePosContArray in the function) you are assinging an instance
what i dont get is why you keep assinging the same element from the array – i have the scirpt doing what i think is expected now
but im not sure what you expect it to do – explain further and i will fix it for you
mark
so you want to freeze all the inital controllers in nested list controllers?
mark
ahhh – wow im slow today – ok i get what you trying to do
so
you want to
- add a list controller
- freeze ititial transform
- (not sure about this one) add another list controller
- inside the second list controller add all the controllers from the array
am i close?
mark