[Closed] store a node to control an object later?
hi, i made this simple script to hide/show an object via a button in another object’s attribute holder.
ca=CustAttributes.getDef $.modifiers[1].Controls
LM=$box001
attributes controls
redefine:ca
(
rollout cbt "Check"
(
checkButton chbtHideMe "Hide Me"
on chbtHideMe changed theState do
(
case TheState of
(
true:
(
LM.isHidden = true
)
false:
(
LM.isHidden = false
)
)
)
)
)
--custAttributes.add $.modifiers[1] ca
my only problem is that when i change the object’s name, i’ll have to change the script, and redefine my CAs. is there a way to do something like store a node, and then call the object for that, instead of its name? how?
thanks in advance
Yes, there is, as you have found what you did is “bad practice”.
You need to create a parameter in you CA of the type maxObject and store a nodeTransformMonitor there.
for example
ca.refNode = NodeTransformMonitor node:obj forwardTransformChangeMsgs:false
obj is the reference object
now to get acces to the node again call it via ca.refNode.node
This is by far the best solution,
-Johan
alright, i added a parameter with this script:
ca=attributes params
(
parameters paras
(
nodepar type:#maxObject
)
)
custAttributes.add $box001 ca
now should i run this
ca.refNode = NodeTransformMonitor node:$box001 forwardTransformChangeMsgs:false
but what should i put in the refNode? if i evaluate like this it will return ‘unknown property refnode in undefined’.
and if i switch refNode with “nodePar” wich is the param name, max will crash when i evaluate… lol
interesting… but idk how to do that. in fact, im so confused, i dont know what you mean by “node” anymore. could you explain a little further please?
thank you
You should really dig deep into the “Scripted Plug-in Clauses” chapter in the mxs help file:
The node can be assigned after the ca has been assigned.
The bool parameter can be linked to any state switching control in the rollout (answers your other post).
ca = attributes controls
(
parameters main rollout:roUI
(
-- Here we store the state
hideState type:#boolean default:false animatable:false ui:chbtHideMe
-- Here we store the node reference
hideNode type:#maxObject
)
rollout roUI "UI Stuff"
(
checkButton chbtHideMe "Hide Reference" height:18 width:155 align:#center
on chbtHideMe changed state do
(
hideNode.node.isHidden = state
chbtHideMe.Text = if state then "Show Reference" else "Hide Reference"
)
)
)
b = box wirecolor:black isSelected:true
b2 = box height:10 width:30 length:30 wirecolor:orange
em = EmptyModifier()
addModifier b em
custAttributes.add em ca
em.controls.hideNode = NodeTransformMonitor node:b2 forwardTransformChangeMsgs:false
Hope this helps,
-Johan
oh, by the way, is it possible to do do this, but to a modifier, instead of the whole object?
im trying to enable/disable modifiers through scripting, but if i call a modifier by name, the same problem occurs as i wont be able to change their name, and if i call them by index number, lets say $.modifiers[1], i wont be able to add new modifiers on top of it, or change the order.
thanks
Just directly store the modifier in the maxObject parameter, no need to use the nodeTransformMonitor there, that tool is only there to make sure the node is not notified when transforms occur slowing down the whole scene, modifiers don’t sent that sort of messages.
hideMod type:#maxObject
hideMod = $someNode.modifiers["some modifier"]
And let me help you out with some modifier disable work too
case state of
(
1 : for m in theMods do ( m.enabled = true; m.enabledInViews = true; m.enabledInRenders = true)
2 : for m in theMods do ( m.enabled = true; m.enabledInViews = false; m.enabledInRenders = true)
3 : for m in theMods do ( m.enabled = true; m.enabledInViews = true; m.enabledInRenders = false)
4 : for m in theMods do ( m.enabled = false; m.enabledInViews = true; m.enabledInRenders = true)
)
Once your there you’ll see it’s helpful
-Johan
this is exactly what i wanted
i even asked for help in another thread for the option to have it disabled in viewport / enabled in render, so its just great
im just having a problem to implement it into my code… lol
maybe im placing it wrong
ca=CustAttributes.getDef $.modifiers[1].controls
attributes controls
redefine:ca
(
parameters params rollout:roll
(
boxState type:#boolean default:false animatable:false ui:boxBut
boxNode type:#maxObject
boxMod type:#maxObject
)
rollout roll "Options"
(
checkbutton boxBut "Hide/Show"
on boxBut changed state do
(
boxNode.node.modifiers[2].enabled = state
)
)
)
--boxMod=$Box001.modifiers[2]
--custAttributes.add $.modifiers[1] ca
--$.modifiers[1].controls.boxNode = NodeTransformMonitor node:$Box001 forwardTransformChangeMsgs:false
the boxNode.node.modifiers[2].enabled = state works, but when i replace it by boxNode.node.boxMod.enabled = state, it wont work, and i get an error when i click the button.
what am i doing wrong?
i know i should learn it more in depth, and i’m trying, but the only time i have to do this is @ work during small breaks, so it might take some time lol
gonna try the 4 cases now