[Closed] Best way to animate visibility of multiple objects with radiobuttons?
That’s actually very close to my original approach, which I find extremely encouraging! Now I just have to figure out what it is that is different about my version that causes Max to crash when I try to render. Gonna be out for most of the day but I’ll noodle around with this tonight and tomorrow if I get the time and let you know if I can figure out what I was doing wrong.
…
Okay, that is strange.
Denis, try running your script exactly as you have it, except replace the boxes with lights. Turn on animation, move to a frame other than zero, and change the radiobutton value. Then try to render the scene.
When I do that, Max crashes. Please let me know if you have the same result.
RadioVisAttr = attributes RadioVisAttr attribID:#(1010101, 2020202) (
parameters params rollout:params (
vis_id type:#integer default:1 animatable:on ui:ui_vis_id
on vis_id set val do (
for node in (refs.dependentnodes this) do (
node.visibility.controller.setexpression (node.visibility.controller.getexpression())
)
)
)
rollout params "Radio Vis" (
radiobuttons ui_vis_id "Vis ID:" labels:#("1", "2", "3") columns:3
)
)
delete objects
--b1 = box name:#b1 pos:[0,0,0] wirecolor:green
--b2 = box name:#b2 pos:[40,0,0] wirecolor:orange
--b3 = box name:#b3 pos:[80,0,0] wirecolor:yellow
b1 = omniLight pos:[0,0,0]
b2 = omniLight pos:[40,0,0]
b3 = omniLight pos:[80,0,0]
bb = #(b1, b2, b3)
attr = createinstance RadioVisAttr
for k = 1 to bb.count do (
b = bb[k]
append b.baseobject.custattributes attr
s = b.visibility = float_script()
b.visibility.controller = s
s.addconstant "id" k
s.addobject "ca" attr
s.setexpression "print id; (refs.dependentnodes this).ishidden = (ca.vis_id != id); 1"
)
select b1
max modify mode
redrawviews()
have you seen how i would do?
everything else is not safe, and i wouldn’t do it. and i don’t want to try it.
I’m saying your solution works fine for boxes, but it does not work for lights.
Actually it works for render for the boxes. It just crashes Max with lights.
if you remember i’ve asked you about a difference between a render and viewport solution.
I thought you meant working for for showing/hiding for render. Not “it will crash Max if you try rendering”. I want to use this as something to hide or show lights or helpers which do not show up in the renderer anyway, so I don’t understand why it would even matter.
Is this really something that can’t be fixed?
it can.
but go several posts above to see where you said that you don’t care.
i’ve just showed you the difference…
the thing has to be solved just right
we’ve discussed the difference between a real-time and a render solution on this forum.
there are properties those were defined as ‘not animatable’ just because… like #kerning of text shape.
you can find in ‘how to’ how Bobo (?) makes it animatable.
but some properties are really NOT ANIMATABLE. one of them is ISHIDDEN
Does this work for what you need?
(
resetMaxFile() #noPrompt
max modify mode
ctrl = plane length:50 width:150 lengthsegs:1 widthsegs:1 wirecolor:white isselected:true
olights =
#(
omnilight name:"L1" pos:[-50,0,5] rgb:red,
omnilight name:"L2" pos:[ 0,0,5] rgb:green,
omnilight name:"L3" pos:[ 50,0,5] rgb:blue
)
CA_LIGHTS_CRTL = attributes CA_LIGHTS_CRTL attribID:#(0, 0)
(
parameters params rollout:params
(
id type:#integer default:1 animatable:on ui:lightID
)
rollout params "Lights Control"
(
radiobuttons lightID " Light ID" labels:#("1", "2", "3")
)
)
custattributes.add ctrl CA_LIGHTS_CRTL #unique
scr = ctrl.visibility = float_script()
ctrl.visibility.controller = scr
scr.AddNode "me" ctrl
for j in olights do scr.AddNode j.name j
expr = "lights = #(L1, L2, L3)
"
expr += "for j = 1 to lights.count do (lights[j].enabled = me.id == j; lights[j].ishidden = me.id != j)
"
expr += "1"
scr.setexpression expr
callbacks.removeScripts id:#ID_0X150C11420X3EFC8235
callbacks.addScript #preRender "for j in lights do j.enabled = true" id:#ID_0X150C11420X3EFC8235
seed 0
with animate on
(
for j = 100 to 0 by (random -5 -10) do at time j ctrl.id = random 1 3
)
completeredraw()
playAnimation()
)
Tested on Max 2011 thru 2017, and it didn’t crash on any version.