PDA

View Full Version : store a node to control an object later?


fael097
11-10-2010, 10:55 AM
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

JHN
11-10-2010, 12:44 PM
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

fael097
11-10-2010, 01:44 PM
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'.

fael097
11-10-2010, 05:09 PM
and if i switch refNode with "nodePar" wich is the param name, max will crash when i evaluate... lol

JHN
11-10-2010, 05:31 PM
I think you have to assign the CA to a node first,

-Johan

fael097
11-10-2010, 05:43 PM
I think you have to assign the CA to a node first,

-Johan

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

JHN
11-10-2010, 06:47 PM
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

fael097
11-10-2010, 10:03 PM
now that helped, thank you so much :)

fael097
11-11-2010, 10:59 AM
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

JHN
11-11-2010, 11:03 AM
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

fael097
11-11-2010, 12:54 PM
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

JHN
11-11-2010, 01:09 PM
Because it takes an index or a name in the modifier array
Why not directly manipulate the boxMod itself the parameter holds an instance of the modifier so manipulate directly.

boxMod.enabled = state

-Johan

fael097
11-11-2010, 01:20 PM
well i tried b4, but wont work aswell. says "unknown property "enabled" in undefined for some reason

JHN
11-12-2010, 09:53 AM
Then you are not storing the modifier in the boxMod property properly.

-Johan

fael097
11-12-2010, 11:52 AM
yeah, i realized that, but i did what you said, could you point what i am doing wrong?

JHN
11-12-2010, 12:03 PM
-- Create a test modifier
b = bend angle:45

-- Add it before the attribute holder, so it gets index 2
addModifier $ b before:1

-- Get the attrib def
ca = CustAttributes.getDef $.modifiers[1].controls

-- redefine it
cc = 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
(
max create mode -- circumvent the ui update problem
boxMod.enabled = not state
max modify mode

)
)
)
-- assign the bend modifier to the boxmod parameter
$.modifiers[1].controls.boxMod = $.modifiers[2]


-Johan

fael097
11-12-2010, 12:24 PM
great :)
heres what i was doing wrong:
instead of
$.modifiers[1].controls.boxMod = $Box001.modifiers[1]
i was typing only
boxMod = $Box001.modifiers[1]
now it works
cheers

also, if you're not sick of chewing maxscript for me: (if you are, thats ok, by now i would aswell)

for my case, this works:
checkbutton boxBut "Hide/Show"
on boxBut changed state do
(
case state of
(
true: ( boxMod.enabled = true; boxMod.enabledInViews = true; boxMod.enabledInRenders = false)
false: ( boxMod.enabled = false; boxMod.enabledInViews = false; boxMod.enabledInRenders = false)
)
)
but i have no clue how to make the 4 options switch work with a checkbutton, wich afaik, its only options were true/false.
checkbutton boxBut "Hide/Show"
on boxBut changed state do
(
case state of
(
1 : for boxMod in theMods do ( boxMod.enabled = true; boxMod.enabledInViews = true; boxMod.enabledInRenders = true)
2 : for boxMod in theMods do ( boxMod.enabled = true; boxMod.enabledInViews = false; boxMod.enabledInRenders = true)
3 : for boxMod in theMods do ( boxMod.enabled = true; boxMod.enabledInViews = true; boxMod.enabledInRenders = false)
4 : for boxMod in theMods do ( boxMod.enabled = false; boxMod.enabledInViews = true; boxMod.enabledInRenders = true)
)
)
idk if thats the right syntax, and/or what to put where is "theMods" since i already switched the "m" for my box modifier.

nonetheless, helped more than enough already. glad you did, thank you one more time
now back to maxscript documentation :)

JHN
11-12-2010, 01:06 PM
As you guessed, the state is a boolean on or off, the case in my example needs an integer 1..4.
So either drop the checkbox and go for something like radiobuttons (what I did) and hook those to an integer parameter or just stick with on/off if that's enough for your needs.

-Johan

CGTalk Moderation
11-12-2010, 01:06 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.