[Closed] enabling buttons in same rollout but seperate group
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?
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.
Wow. Clear and Comprehensive answer as usual. Thanks again, St.Bobo.