Scripting Question: Checkbox to Control Visibility (and other things)

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 07 July 2013   #1
Scripting Question: Checkbox to Control Visibility (and other things)

Hi guys-

I'm trying to build a dummy object with a checkbox custom attribute to swap out the visibility of two objects. So for example:

"ON" state, checkbox is checked on dummy object:
first mesh visibility = 1
second mesh visibility = 0
point light intensity = 1.0

"OFF" state, checkbox is checked on dummy object:
first mesh visibility = 0
second mesh visibility = 1
point light intensity = 0

And I want to wire the dummy with the attribute to the different objects as well, so when I move the dummy, the meshes and light follow the dummy around, so I can place the item, and then tick the box to flip the states. Relative newb to maxscript, thank you in advance for your help!
__________________
www.zephyrstar.com
 
Old 07 July 2013   #2
What about something like this?

(
	local master = Dummy prefix:"Master"

	in master
	(
		local mesh1 = Plane pos:[-10,0,0] dir:x_axis
		local mesh2 = Plane pos:[10,0,0] dir:-x_axis
		local light1 = OmniLight pos: [0,0,10]
	)

	local def = attributes controls attribID:#(0x736560da, 0x32bcf387)
	(
		parameters params rollout:main (flip type:#boolean ui:chxFlip)
		rollout main "Controls" (checkBox chxFlip "Flip: ")
	)

	custAttributes.add master def
	master.flip.controller = boolean_float()
	mesh1.visibility = master.flip.controller
	mesh1.visibility.controller = master.flip.controller -- used to work with single assignment in earlier max versions...

	local flippedCtrl = float_script()
	flippedCtrl.addTarget #flip mesh1[1]
	flippedCtrl.setExpression "1 - flip"
	mesh2.visibility = flippedCtrl
	mesh2.visibility.controller = flippedCtrl -- same here

	light1.multiplier.controller = flippedCtrl
)
__________________
Scripts :: linkedin
 
Old 07 July 2013   #3
Thank you!
I will play around with this and get back to you.
I appreciate the help!
__________________
www.zephyrstar.com
 
Old 07 July 2013   #4
So....how would this work in the wire parameters?

I can connect them up, but I can't get the checkbox to switch the visibilities on and off. Maybe it's variable types?

So:

Dummy
>cust attribute>checkbox (named light_on)

is wired to

Box001
>visibility

So I think I need to have the control direction going from the Dummy object to the Box object, but in the box object's code I have:

if light_on = true then $.visibility = 1.0 else if light_on = false then $.visibility = 0.0

Does not seem to work this way?

Sorry, told you I was a newbie
__________________
www.zephyrstar.com
 
Old 07 July 2013   #5
Look at what I posted, it already works. There's no wiring, some controllers are instanced (so copy - paste it if you are doing it via UI), some scripted - it could be changed to parameter wiring, eitherway you have to assign the controller to flip first. What might be kind of confusing is that unless a viewport redraw occurs (for example when you change selection or force the update via script) you won't see the change happen.
__________________
Scripts :: linkedin
 
Old 07 July 2013   #6
Figured it out. Many thanks for your code, I really appreciate your help.
__________________
www.zephyrstar.com
 
Old 07 July 2013   #7
One quick question, if I have wired this, how can I add a redraw command so that every time the checkbox is ticked the object being updated redraws itself? Thanks!
__________________
www.zephyrstar.com
 
Old 07 July 2013   #8
Just discovered dragging the time slider updates it as well.
__________________
www.zephyrstar.com
 
Old 07 July 2013   #9
Just an update in case anyone else runs into this, as I googled to no avail.
Sometimes the simplest method is overlooked first.

What I was trying to make, is one of those audio control surfaces, the ones with the colored lit buttons in a grid. I created 6x6 boxes, 2 meshes each, one for on, one for off, and a dummy for each one with a checkbox to flip the visibility of each and turn on a light for each.

Basically all I had to do was wire my custom attribute on the dummy (light_on) to the two boxes, have the direction point from the dummy to the two box meshes, then on each of the boxes, for the "on" state mesh, it's just wired directly to it, no expression needed. For the "off" state mesh, it's wired directly to it, but the expression is 1-light_on is the state. This ensures they flip back and forth. Same with the light.

Good stuff.
__________________
www.zephyrstar.com
 
Old 07 July 2013   #10
Yes, that's basically what I did, only using wire parameters instead of controller instance and expression controller. It doesn't really matter here, just note that controller instance is the most straightforward (and the fastest) way of direct connection (in Track View you'd copy and paste the controller as instance), and expression controllers are also preffered choice to maxscript-based controllers when the expression is so simple.
__________________
Scripts :: linkedin
 
Old 07 July 2013   #11
#1
Originally Posted by ZephyrStar: What I was trying to make, is one of those audio control surfaces, the ones with the colored lit buttons in a grid. I created 6x6 boxes, 2 meshes each, one for on, one for off, and a dummy for each one with a checkbox to flip the visibility of each and turn on a light for each.


#2
Originally Posted by ZephyrStar: One quick question, if I have wired this, how can I add a redraw command so that every time the checkbox is ticked the object being updated redraws itself?


#1
i don't recommend to use two controls in UI for ON/OFF functionality. It makes controller-to-ui control wiring much more complicated than the one control (checkbox, checkbutton) solution (specially if you want to have this parameter animatable).

#2
use ca parameter's set event handler and call notification (notifyDependents this partID:<name> msg:<int> propogate:<bool>)...

here is a sample:
global visAttr = attributes visAttr
 (
 	parameters params rollout:params
 	(
 		visible type:#boolean default:on ui:ui_visible
 		on visible set val do notifydependents this partID:#display 
 	)
 	rollout params "Parameters"
 	(
 		checkbutton ui_visible "Visible" width:152 align:#right offset:[8,0]
 	)
 )
 with redraw off
 (
 	delete objects
 	b = box isselected:on
 	custattributes.add b visAttr baseobject:on
 	b.visibility = Boolean_Float()
 	b.visibility.controller = b.baseobject.visAttr.visible.controller = Boolean_Float()
 )

Last edited by denisT : 07 July 2013 at 02:19 PM.
 
Old 07 July 2013   #12
Swordslayer: thank you for that clarification. As I get to more of this scripting business I will definitely keep this in mind.

denisT: thank you as well. This is what I ended up going with, I have the one checkbox that toggles. So far so good

Thanks again guys.
__________________
www.zephyrstar.com
 
Old 07 July 2013   #13
Originally Posted by denisT: i don't recommend to use two controls in UI for ON/OFF functionality.

but... for anyone who wants to see two-controls ON/OFF solution here is a sample:

 global visAttr = attributes visAttr
 (
 	parameters params rollout:params
 	(
 		visible type:#boolean default:on ui:ui_visible
 		hidden type:#boolean default:off ui:ui_hidden
 		on visible set val do notifydependents this partID:#display 
 		on hidden set val do notifydependents this partID:#display 
 	)
 	rollout params "Parameters"
 	(
 		group "Visibility: "
 		(
 			checkbutton ui_visible "ON" width:71 align:#left offset:[-4,0] across:2
 			checkbutton ui_hidden "OFF" width:71 align:#right offset:[4,0]
 		)
 	)
 )
 with redraw off
 (
 	delete objects
 	b = box isselected:on
 	attr = createinstance visAttr
 	append b.baseobject.custattributes attr
 	attr.visible.controller = Boolean_Float()
 	attr.hidden.controller = Boolean_Float()
 	paramwire.connect2way attr[#visible] attr[#hidden] "1-hidden" "1-visible"
 	
 	b.visibility = Boolean_Float()
 	
 	b.visibility.controller = attr.visible.controller
 )
 
 
Old 07 July 2013   #14
Thread automatically closed

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.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 09:14 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.