PDA

View Full Version : enabling buttons in same rollout but seperate group


floatingworld
07-24-2011, 08:32 AM
Hi. I'm rying to create a conditional enable for a button which is in a seperate group of a rollout. Not sure how to reference a button which is in another group...I tried this but it doesn't work:

on openconnectmorphC pressed do
(
rollout myrollout "Connectmorph" width:1700 height:50 ;
(


group " Select Morphs " (
Select
Button UprRight "Default" width:50 height:50 offset:[0,0] align:#right across:3;

on UprRight pressed do(

somefunction ()

CornersConnect.enabled = true
)
--messagebox (Upr+" node") );

)


group "Connections" (

button CornersConnect "Connect Corners" width:200 offset:[10,-26]; enabled:false

)

)
(
on CornersConnect pressed do(

someotherfunction()
)




)

createDialog myrollout 500 450 -- set as a dialogue instead of a rollout


)




Can I use a function for enabled, like I can for filter?

lo
07-24-2011, 10:55 AM
wow, that is some messy code you got there.

All controls are locals of the rollout, Groups are only visual cues for the user, they do not change the hierarchical structure of the rollout.

floatingworld
07-24-2011, 11:48 AM
yes I know its messy - I probably shouldn't have posted it...it's just original code with distracting irrelevant stuff deleted for clarity....If you assure me that I can toggle enables over groups within a rollout, I guess I will accept that and figure out why it's not working in my code. Thanks.

lo
07-24-2011, 01:31 PM
yeah it should work as long as the button has been defined.
Please post the code if it's still not working.

floatingworld
07-24-2011, 04:26 PM
well I tried this but it doesn' work:(I apologize for the horrible formatting and messiness):


rollout myrollout "Connectmorph" width:1700 height:50 ;
(

group " Select Morphs Select slider slots"(

Button UprRight "PressMe" width:50 height:50 offset:[0,0] align:#right across:3;
--label lbl2 "Unassigned" width:40 height:10; offset:[20,-60];

on UprRight pressed do(

Corners.enabled = true;

)
--messagebox (Upr+" node") );

--messagebox (LwrMid+" node")
);



group "Connections" (


Button Corners "Connect Corners" width:50 height:50 offset:[10,-30]; enabled:false

--button CornersConnect "Connect Corners" width:200 offset:[10,-26]; enabled:false
)
createDialog myrollout 200 150 -- set as a dialogue instead of a rollout)


whereas this does work:(not what I want)

rollout myrollout "Connectmorph" width:1700 height:50 ;
(

group " Select Morphs Select slider slots"(

Button UprRight "PressMe" width:50 height:50 offset:[0,0] align:#right across:3;
Button Corners "Connect Corners" width:50 height:50 offset:[10,-30]; enabled:false


on UprRight pressed do(

Corners.enabled = true;

)
--messagebox (Upr+" node") );

--messagebox (LwrMid+" node")
);



group "Connections" (


--button CornersConnect "Connect Corners" width:200 offset:[10,-26]; enabled:false
)
createDialog myrollout 200 150 -- set as a dialogue instead of a rollout)

lo
07-24-2011, 04:41 PM
As I said earlier, it will work if the button is already defined.
You must define both the buttons, then define the event handlers for both, if you are referencing the other button in the event handler. There is no necessity for the event handler to be inside the group clause.

floatingworld
07-24-2011, 10:41 PM
ok got it..thanks..

Bobo
07-25-2011, 01:49 AM
rollout myrollout "Some rollout"
(
group "Some Group"
(
Button UprRight "PressMe" width:160
)
group "Another Group"
(
Button Corners "Connect Corners" width:160 enabled:false
)

--This must be AFTER corners has been defined in order to "see" it,
--otherwise you will get
-->> MAXScript Rollout Handler Exception: -- Unknown property: "enabled" in undefined <<
--Also outside of the group's body to work in older Max versions:
on UprRight pressed do
(
Corners.enabled = true
)

on Corners pressed do
(
Corners.enabled = false
)

)--end rollout

createDialog myrollout 200 110

denisT
07-25-2011, 01:59 AM
[CODE]rollout myrollout "Some rollout"
(
...

Tu deviens responsable pour toujours de ce que tu as apprivoisé.

Bobo
07-25-2011, 02:24 AM
Tu deviens responsable pour toujours de ce que tu as apprivoisé.

I landed 5 hours ago from a trans-continental trip from Sofia to Vancouver.
I suspect a jury would consider me not responsible for my own actions at this moment ;)

denisT
07-25-2011, 03:10 AM
I landed 5 hours ago from a trans-continental trip from Sofia to Vancouver.
I suspect a jury would consider me not responsible for my own actions at this moment ;)
"You are a saint." (Brother Lo)
;)

lo
07-25-2011, 04:41 AM
Tu deviens responsable pour toujours de ce que tu as apprivoisé.

I *almost* got that without google translate :cool:

"You are a saint." (Brother Lo)

Rest assured, Denis, there is a Halo awaiting you as well. If it wasn't for the both of you, me and many others here would still be at "Hello World" :beer:

floatingworld
07-25-2011, 08:17 AM
Oh hi bobo...thanks for that....very clear. tres clair. Yes the pope of coding is going to canonize you. One last thing - am I able to create a function for enabling in the same way I can for filter?

Bobo
07-25-2011, 10:12 AM
...Am I able to create a function for enabling in the same way I can for filter?

Not is the same way as the filter function of a pickbutton which is triggered internally to figure out whether an object is valid or not for picking. But it is possible using a general event callback.

It is also built in as an event handler of MacroScripts (on isEnabled return ...) if you want to disable a toolbar button or menu item.


Here is an example of a script that actually does something, but is meant mainly as illustration:


(
global myrollout_uniquename
try(destroyDialog myrollout_uniquename )catch()
rollout myrollout_uniquename "Some rollout"
(
group "Some Group"
(
Button btn_SomeButton "Select Point Helpers..." width:160 enabled:false
)

fn updateUI =
(
local filterState = selection.count > 1 and (for i in selection where classof i == Point collect i).count == selection.count
btn_SomeButton.enabled = filterState
btn_SomeButton.text = if filterState then "Parent " + selection.count as string + " Point Helpers!" else "Select Point Helpers..."
)

on btn_SomeButton pressed do
(
--First unlink all selected point helpers:
for i = 1 to selection.count do
selection[i].parent = undefined
--Parent the points in the order of selection:
for i = 2 to selection.count do
selection[i].parent = selection[i-1]
select selection[1] --select the root of the hierarchy
-- this will update the UI and disable the button!
)

on myrollout_uniquename open do
(
--when the dialog is created/rollout is opened,
--register a callback unique to the rollout
callbacks.addScript #selectionSetChanged "myrollout_uniquename.updateUI()" id:#myRollout_uniquename_Callback
updateUI() --and update the UI to reflect current selection
)
on myrollout_uniquename close do
(
--when the dialog is closed/destroyed, unregister the callback:
callbacks.removeScripts id:#myRolloutCallback
)

)--end rollout
createDialog myrollout_uniquename 200 60
)--end script


Create two or more Point Helpers. Create some other objects like Geometry primitives, lights etc. Then evaluate the script.

*Select one Point Helper - the button will be grayed out. If any other types of objects are selected, or nothing is selected, it will be still disabled.
*Hold down Ctrl and select a second Point Helper - now you have exactly two Point Helpers and the button will be enabled. You can keep on adding Point Helpers to the selection - if you click anything else, the button will go gray again.
*Once you have two or more Point Helpers and nothing else, press the button.
RESULT: The Point Helpers will be first unparented, then parented in a chain in the order of selection (since the MAXScript 'selection' collection stores the objects in the order of selection!) The first selected Point Helper will be selected, the rest will be deselected, which will trigger the callback and the button will go gray again until you select 2 or more Point Helpers (in a different order). You can move the Helpers to see how they are linked.

If you close the dialog, the callback will be unregistered.
Remember to use unique names for both the rollout and the callback's ID name to avoid naming collisions with other scripts. Also note that this script will try to destroy the dialog it is about to create so you can have exactly one instance of the rollout shown at any time.

floatingworld
07-25-2011, 11:29 AM
Wow. Clear and Comprehensive answer as usual. Thanks again, St.Bobo.

CGTalk Moderation
07-25-2011, 11:29 AM
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.