[Closed] Maxscript and Mouse Drag
Hello EveryOne,
I have been trying to do this, but I guess I need some help
I would like to assign a hotkey on mouse drag object with ctrl key pressed…
How do I go about this?
Just like the clone tool is in 3ds Max, I would like to open a dialog box when I click ctrl key and drag an Object…
Can you please help me out with this?
Thank You in Advance.
Here is a possible way:
*A general event callback is monitoring changes in the selection and when you select new objects, it registers a when callback to monitor transforms of the selected objects.
*When the selected objects are transformed (moved/rotated/scaled) and the Control key is pressed and the Left Mouse Button is not pressed, a modal dialog is opened.
In the following example, the dialog provides a button to assign a random wirecolor to the selected objects, and another one to cancel. This is just a demo, you can do anything that is allowed by MAXScript in that context…
(
global OpenDialogOnMoveCtrl_Rollout --this will hold the rollout for the dialog
global OpenDialogOnMoveCtrl_Function --this will hold the function
rollout OpenDialogOnMoveCtrl_Rollout "Assign Random Color" --this is the rollout
(
button btn_randomColor "Generate Random Object Color!" width:200 height:30
button btn_closeDialog "Cancel" width:200
on btn_randomColor pressed do --if the first button is pressed,
(
selection.wirecolor = random black white --assign a random color to all selected objects
destroyDialog OpenDialogOnMoveCtrl_Rollout --and close the dialog
)--end on
on btn_closeDialog pressed do --of the second button is pressed,
(
destroyDialog OpenDialogOnMoveCtrl_Rollout --just close the dialog without doing anything
)
)
fn OpenDialogOnMoveCtrl_Function = --this function is called by general event callback and registers a transform handle
(
deleteAllChangeHandlers id:#OpenDialogOnMoveCtrl --remove previous handlers
if selection.count > 0 do --if the selection is not empty,
(--then register event handler to open dialog if the selection was transformed and control key was pressed
when transform selection change id:#OpenDialogOnMoveCtrl handleAt:#redrawViews do
(
--only open dialog if Control key is down and Left mouse button is up:
if keyboard.controlPressed and not mouse.buttonStates[1] do
(
createDialog OpenDialogOnMoveCtrl_Rollout 210 70 modal:true --open dialog as modal, blocking main thread
)--end if control pressed
)--end when
)--end if
)
callbacks.removeScripts id:#OpenDialogOnMoveCtrl --remove general callbacks with this ID
--call function to register transform event handle for the current selection:
callbacks.addScript #selectionSetChanged "OpenDialogOnMoveCtrl_Function()" id:#OpenDialogOnMoveCtrl
)
Thank You so much BOBO for the reply,
I tried running the script and it returns an error:
– Error occurred in anonymous codeblock; filename: none; position: 0
– Frame:
– OpenDialogOnMoveCtrl_Function: undefined
>> MAXScript Callback script Exception: – Type error: Call needs function or class, got: undefined <<
Thank You for the Reply!!!
Try again.
I had the function already defined as global, but forgot to include an explicit declaration in the local scope of the script. So it was working for me, but would fail anywhere else.
I added a second line to the script to declare the variable.
Wow!!! I nevery knew if we could even use Global with a Function!!!
Thanks a ton… Solved my problem…
When I run this, all it does is report ok in the listener.
Am I doing something wrong?
I’m trying to learn callbacks from this.
No Its perfectly fine… So when you hold down the ctrl Key on the Keyboard and move the object, It will popup a dialog box!!! What Listener says is that it has successfully run the script and has found no errors.