Pressing a Button in the Max UI


Hello, I am looking for a way to simulate pressing a button on the 3DS Max UI through Maxscript. The Transform Type-In button to be precise. Here is a picture of the button in question:

I can’t use UIAccessor.PressButtonByName because it doesn’t have a name. My attempt to solve the problem was using this code:

n = 1
for i in windows.getChildrenHWND #max do
	n += 1
	print (i[5] + "___ID:" + n as string)

This would spit out the ID of the text “X:”. I then try executing
UIAccessor.PressButton (windows.getChildrenHWND #max)[n-3][1], however it doesn’t seem to work. Which is odd, since when I put in n-5, which should correspond to the “Selection Lock Toggle” button, it works just fine, as well as n-7 for the “Isolate Selection Toggle” and etc.
For some reason I am not able to access this button.
Do any of you have any idea what the problem might be? Any help would be greatly appreciated :slight_smile:


Not sure why the UIAccessor command isn’t working for that button…an alternative that worked for me is:

 inx = 339 --the ID of the "X:" static control minus 2, which is the transform type-in button
 hwnd = (windows.getChildrenHWND #max)[inx]
 windows.sendmessage hwnd[1] 0x0201 0x0001 0 --mouse button down
 windows.sendmessage hwnd[1] 0x0202 0x0001 0 --mouse button up


it’s a ‘check-button’ functionally button. it catches mousedown event instead of mouseclick.

you can see that it works on ‘mouse down’ and doesn’t need ‘up’. so it’s enough to send only WM_LBUTTONDOWN message:

windows.sendMessage <button_hwnd> WM_LBUTTONDOWN 0 0  -- WM_LBUTTONDOWN  = 0x0201


But the other two buttons alongside it are also checkbuttons, and the UIAccessor code works fine for them…


Thank you for your help ivanisavich :slight_smile: No idea what is happening behind the scenes to cause that button to not behave like all the rest, but regardless I’m glad you managed to find a solution! ^^


For any ICustButton control there’s a much better way to do this
It allows you to easily access lots of button properties and methods.

fn ToggleTransformTypeInRelativeMode = 
	local g = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
	local hwnd = undefined
	local GetResID = uiaccessor.GetWindowResourceID
	for c in windows.getChildrenHWND g.coreinterface7.StatusPanelHWnd while hwnd == undefined where c[4] == "CustButton" and GetResID c[1] == 40716 do hwnd = c[1]
	if hwnd != undefined do
		local btn = g.GetICustButton (dotnetobject "system.intptr" hwnd)		
		local state = not btn.IsChecked		
--		show btn
--		showMethods btn
		btn.SetCheck state		
		g.ReleaseICustButton btn
                -- returning current state of the button


.CaptionText : <System.String>, read-only
.CurFlyOff : <System.Int32>, read-only
.DADMgr : <Autodesk.Max.IDADMgr>
.HighlightColor : <System.Drawing.Color>
.Hwnd : <System.IntPtr>, read-only
.Implementation : <System.Object>, read-only
.INativeObject__Handle : <System.IntPtr>, read-only
.IsChecked : <System.Boolean>, read-only
.IsEnabled : <System.Boolean>, read-only
.MacroButtonData : <Autodesk.Max.IMacroButtonData>
.TextLength : <System.Int32>, read-only

.Enable <System.Boolean>onOff
.Enable2 <System.Boolean>onOff
.<System.Boolean>Equals <Autodesk.Max.IInterfaceServer>other
.<System.Boolean>Equals <System.Object>obj
.[static]<System.Boolean>Equals <System.Object>objA <System.Object>objB
.<System.IntPtr>Execute <System.Int32>cmd <System.UIntPtr>arg1 <System.UIntPtr>arg2 <System.UIntPtr>arg3
.<Autodesk.Max.IBaseInterface>GetInterface <Autodesk.Max.IInterface_ID>id
.GetText <System.String&>text
.GetText <System.String>text <System.Int32>ct
.[static]<System.Boolean>ReferenceEquals <System.Object>objA <System.Object>objB
.SetButtonDownNotify <System.Boolean>notify
.<System.Boolean>SetCaptionText <System.String>text
.SetCheck <System.Boolean>checked_
.SetCheckHighlight <System.Boolean>highlight
.SetCurFlyOff <System.Int32>f <System.Boolean>notify
.SetFlyOff <System.Int32>count <Autodesk.Max.IFlyOffData>data <System.Int32>timeOut <System.Int32>init <System.Int32>dir <System.Int32>columns
.SetIcon <Autodesk.Max.IMaxBmpFileIcon>pIcon <System.Int32>w <System.Int32>h
.SetImage <System.IntPtr>hImage <System.Int32>iOutEn <System.Int32>iInEn <System.Int32>iOutDis <System.Int32>iInDis <System.Int32>w <System.Int32>h
.SetInIcon <Autodesk.Max.IMaxBmpFileIcon>pInIcon <System.Int32>w <System.Int32>h
.SetRightClickNotify <System.Boolean>notify
.SetText <System.String>text
.SetTooltip <System.Boolean>bEnable <System.String>text
.SetType <Autodesk.Max.CustButType>type
.UpdateEnableState <Autodesk.Max.IAnimatable>anim <System.Int32>subNum