Notifications
Clear all

[Closed] Two little questions,Thanks

Hello,I have two questions Please see picture,Thanks

12 Replies
showTexturemap meditMaterials[1] on
 
	
fn toggleTransformTypeIn = (
		
		WM_LBUTTONDOWN = 0x0201
		WM_LBUTTONUP = 0x0202
  
   global _user32 =
		  (
			source = ""
			source += "using System;
"
			source += "using System.Runtime.InteropServices;
"
			source += "class User32
"
			source += "{
"
			source += "	[DllImport(\"user32.dll\")]
"
			source += "	public static extern int PostMessage(Int32 hWnd, int wMsg, int wParam, int lParam);
"
			source += "}
"
		  
			csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
			compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
							
			compilerParams.GenerateInMemory = on
			compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
			compilerResults.CompiledAssembly.CreateInstance "User32"
		  )
		  
		transformBtnHWND = (for m in (windows.getchildrenhwnd #max) where m[4] == "Static" and m[5] == "X:" collect (m[1] - 4))[1]
  
		if transformBtnHWND != undefined do (
			
			_user32.postmessage transformBtnHWND WM_LBUTTONDOWN 0 0
			_user32.postmessage transformBtnHWND WM_LBUTTONUP 0 0
			
		)
		
)

toggleTransformTypeIn()

Thanks Serejah! The second code run wrong,

– Error occurred in toggleTransformTypeIn(); filename: ; position: 911; line: 25
– Frame:
– csharpProvider: dotNetObject:Microsoft.CSharp.CSharpCodeProvider
– compilerParams: dotNetObject:System.CodeDom.Compiler.CompilerParameters
– WM_LBUTTONDOWN: 513
– maxchilds: undefined
– WM_LBUTTONUP: 514
– source: “using System;
using System.Runtime.InteropServices;
class User32
{
[DllImport(“user32.dll”)]
public static extern int PostMessage(Int32 hWnd, int wMsg, int wParam, int lParam);
}

– transformBtnHWND: undefined
– compilerResults: dotNetObject:System.CodeDom.Compiler.CompilerResults
– No “map” function for undefined

Try this. Should work in any Max version:

fn ToggleTransformTypeIn =
(
	WM_LBUTTONDOWN = 0x0201
	WM_LBUTTONUP   = 0x0202
	
	getID = uiaccessor.getwindowresourceid
	children = windows.getchildrenhwnd #max
	
	for j in children where j[4] == "CustButton" and getID j[1] == 40716 do
	(
		windows.sendmessage j[1] WM_LBUTTONDOWN 0 0
		windows.sendmessage j[1] WM_LBUTTONUP 0 0
		return true
	)
	return false
)

ToggleTransformTypeIn()

this was answered couple time on this forum… a dirty solution for the toggling the button is:


xhwnd = for c in (windows.getchildrenhwnd #max) where c[5] == "X:" do exit with c[1] -- find a label of x - type-in spinner
bhwnd = uiaccessor.getprevwindow (uiaccessor.getprevwindow xhwnd) -- find window two positions before (previous). it's the button
windows.postmessage bhwnd 0x0201 0 0  -- WM_LBUTTONDOWN -- send message LEFT-MOUSE-PRESSED
windows.postmessage bhwnd 0x0202 0 0  -- WM_LBUTTONUP -- send message LEFT-MOUSE-RELEASED
  

Jorge’s method looks cleaner, if MAX keeps the same resouce ID for this button from version to version

1 Reply
(@polytools3d)
Joined: 11 months ago

Posts: 0

As far as I could test, it has the same ID from Max 2011 to 2017.

i remember LO posted a solution how to get state of this button

So many things on this forum… Disn’t know about it. Are you talking about this thread?

Here are two little functions to GET/SET the Transform Type-In state for Max 2014+. You should wrap this up in a nice structure, and could also add several more methods.

(
	local iGlobal = (dotnetclass "Autodesk.Max.GlobalInterface").Instance

	fn GetTransformTypeInState =
	(
		getID = uiaccessor.getwindowresourceid
		children = windows.getchildrenhwnd #max
		
		for j in children where j[4] == "CustButton" and getID j[1] == 40716 do
		(
			hwnd = dotnetobject "System.intPtr" j[1]
			return (iGlobal.GetICustButton hwnd).IsChecked
		)
		return undefined
	)
	
	GetTransformTypeInState()
)
(
	local iGlobal = (dotnetclass "Autodesk.Max.GlobalInterface").Instance

	fn SetTransformTypeInState state:true =
	(
		getID = uiaccessor.getwindowresourceid
		children = windows.getchildrenhwnd #max
		
		for j in children where j[4] == "CustButton" and getID j[1] == 40716 do
		(
			hwnd = dotnetobject "System.intPtr" j[1]
			(iGlobal.GetICustButton hwnd).SetCheck state
		)
	)
	
	SetTransformTypeInState state:true
)

thanks for some useful tips guys

Page 1 / 2