Notifications
Clear all

[Closed] addNewKey in a loop misses objects

 rdg

Hi,

it’s been a long time …

I set keys for some 100 objects in a loop on their scale controller.
But even if I have “Set Key” enabled, the loop misses randomly objects.
I now see that the problem is that one object gets 1 instead a 100 into the value.

this a snippet:

 tempItem.position.controller.weight[3].controller = Bezier_Float()
   addNewKey tempItem.position.controller.weight[3].controller.keys 25f
   addNewKey tempItem.position.controller.weight[3].controller.keys 100f
  tempItem.position.controller.weight[3].controller.keys[1].value = 1
   tempItem.position.controller.weight[3].controller.keys[2].value = 0
  sortKeys tempItem.position.controller.weight[3].controller

99 of 100 object get the correct values, but one always gets a 0.1 …
in the GraphEditor the keys is on 1 instead on 100 like all others …

Any idea how to tackle this?

Cheers,

Georg

8 Replies
 rdg

I should maybe add that it is a random object that get’s the wrong values.
Everytime I run the script it is different.

A gc() after the loop didn’t help

All I currently can do to solve this is run a second loop after setting the keys. Trying to find the objects that get messed up and correct the value.
Interestingly this time the key needs to be set in a 1…100 range instead of 0…1 while creating it.

I am confused.

can’t say I’m seeing any such error – but we’re not generating the same objects; can you post a more complete example?
Also… which version of 3ds Max are you using?


-- this seems to work fine?
for i = 1 to 1000 do (
	-- generation code
	tempItem = point()
	tempItem.position.controller = position_list()
	tempItem.position.controller.available.controller = Position_XYZ()
	tempItem.position.controller.available.controller = Position_XYZ()
	tempItem.position.controller.available.controller = Position_XYZ()

	-- original code
	tempItem.position.controller.weight[3].controller = Bezier_Float()
	addNewKey tempItem.position.controller.weight[3].controller.keys 25f
	addNewKey tempItem.position.controller.weight[3].controller.keys 100f
	tempItem.position.controller.weight[3].controller.keys[1].value = 1
	tempItem.position.controller.weight[3].controller.keys[2].value = 0
	sortKeys tempItem.position.controller.weight[3].controller
)

 rdg

Hi Richard,
thanks for having a look!
I am using MAX 9 SP2 32bit.
I’ll strip down a more complete example and also run your code.

just checked in 9×32 here… ran a bit slower, but same result… only keyframes generated are at 25 and 100 with values of 100 and 0 respectively… as far as I can tell

 rdg

I attached a version of my script that produces the error.
The screenshot shows that boxes that gather around the center didn’t get the 100 but just 1% of the weight …

It’s probably a noobish error, but I am lost …

hmmm… wish I could make that thing happen consistently…

Anyway, it looks like 3ds Max somehow ‘forgets’ that it should be parsing the controller’s value from the 0.0 … 1.0 range into the 0.0 … 100.0 range. You can actually see this on the objects that appear to be okay… you’re assigning values of 1.0 to the keys, but when you then try to get the value later…

$.position.controller.weight[2].controller.keys[1].value

…you get the return value 100.0 … ho-hum

Re-assign the controller type…

$.position.controller.weight[2].controller = Bezier_Float()

…and check again, and you get the proper return value of 1.0.

So the above may be how to fix things after the fact (re-assign the controller type), but I’m not too sure why what happens… happens in the first place.

 rdg

Well, I am glad you can reproduce this.
I have some “checks of checks of checks” in my code but this becomes rather inefficient.

Speaking about efficiency.
It’s probably better to setup one controller, make sure it’s correct and assign it to the copied boxes.
Then just change the values.
And maybe get rid of the weighting and just use a bezier curve

Thanks for having a look!

Georg

definitely more efficient I’d still do that re-assigning bit, though… just in case that 1 controller you’d create would still be messed up :>