Notifications
Clear all

[Closed] PLEASE HELP! very simple yet I can't get it to work

This is probably very simple, but as I am just a beginer to MS i don’t really know how to do it. It goes like this: I need to make an amount of cubes with a bend modifier disapear when they reache a certain bend angle. (say 90 degrees). I managed to get it to work on ONE cube with this script:

[i]b = $Box01

for i = 1 to 100 do
(
slidertime=i

if b.bend.angle==90
then b.visibility = false
else b.visibility = true
)[/i]

But when I try to use one of these two options to get the thing working with ALL the cubes:

b = $Box*
or
[b][i]b = $Box* as array

[/i][/b]It doesn’t work and goes:
“– Error occurred in i loop
– Frame:
– i: 1
– Unknown property: “Bend” in #(and here comes the list of all boxes)

anyone knows how to make this thing work??
I have a tight schedule and this one can make things much faster for me.

thanks for any help,

Liron

5 Replies

Hi,

Looks like not all your boxes have bend modifier. You can filter them like this:

for i in gometry where (for f in i.modifiers where classOf f == bend collect 0).count != 0 collect i

Light

Hi Light,
Thanks for the quick response… but this is not the situation – i checked to see – and all of my boxes have a bend modifier to them – any other options?

Liron

Haven’t looked at your for loop, you are right. You need to say something like this:

for i in $box* do i.bend.angle = 90

Light

Getting properties is not a mapped function, while setting properties (assignment) is.
So you cannot say
theBend = $Box*.bend
but you can say
$Box*.material = standard()

This is why you need another loop through all objects in the collection to affect them one by one.

I am not sure why you set the sliderTime. You could use the AT TIME context, which will make the script orders of magnitude faster.

Also, do you want the visibility to be ANIMATED when the angle reaches 90 degrees? Otherwise your code does not make sense right now, as it would always keep the visibility based on the LAST frame of the test (100). So looping through 100 frames does not do anything, the final result will always be based on the result on the last frame.

To ANIMATE the visibility, you have to jump through a couple of hoops, because the .visibility property was implemented incorrectly in 3D Studio MAX 1.0 and caused the MAXScript exposure to defy any logic and works nothing like any other property since R2.

b = $Box* as array --collect all boxes
 --this forces the creation of the visibility track for all boxes
 --(it does not exist initially when a node is created!)
  b.visibility = true 
 for t = 1 to 100 do --loop through time
 (
 	for o in b do --loop through the objects
 	(
 		theKey = addNewKey o.visibility.controller t --set a key at the current time
 		--at the current time, set the key value to -1 if angle is equal or greater than 90
 		--or to 1 if it is below the threshold. This does NOT check whether .bend exists...
 		at time t theKey.value = if o.bend.angle >= 90 then -1 else 1
 	)--end o loop
 )--end t loop

It might be a good idea to make sure the Bend modifier actually exists, or at least place that part of the code in try()catch() context to trap any errors caused by missing bend modifiers…

NOTE that using WITH ANIMATE ON will not work for the visibility track when a bezier_float() controller is assigned to it, that’s why I used explicit keyframe creation…

Originally, the .visibility track used a so-called On_Off controller. MAXScript was designed to set keys automatically for that controller class, and the .visibility property still returns true or false. But since people wanted objects to appear/disappear gradually, the default controller type was changed to bezier_float(). So now if you set a visibility value via MAXScript, a bezier_float controller is assigned automatically. Unfortunately, it makes it impossible to set the on_off() controller class AT ALL via MAXScript. If the track was assigned an On_off() controller manually (by selecting the visibility track and then using Assign Controller from the QuadMenu), the following script WOULD work:

b = $Box* as array
 for t = 1 to 100 do
 	for o in b do 
 		at time t with animate on o.visibility = not o.bend.angle >= 90 
 

But as it is now, this cannot be achieved via pure scripting. Autodesk is aware of the mess, but there is not much that can be done as it was implemented incorrectly even before there was MAXScript to care for in the first version of Max.

Thanks bobo, this really helped explain a few bumps i had… kept banging my head against the wall asking “why oh why”. Your script does the trick though – so thanks for that too!

Yey!

Liron