Notifications
Clear all

[Closed] Render to Texture Lightmaps using the Window Struct Methods

After many trials and tribulations, I decided there were too many issues in the maxscript functions to lightmap. So, I’m planning to use the windows struct to send click messages and such to emulate the process that a user would take to render to texture lightmaps. I just started on this and here is my script so far:


   --Message constants
  global BM_GETSTATE = 0xF2
  global BM_CLICK	= 0xF5
  global BM_SETCHECK = 0xF1
  global BST_CHECKED = 0x1
  global BM_SETSTATE = 0x00F3 
  
  
  fn renderLightmap obj fPath =
  (
  	if obj == undefined do 
  	(
  		messageBox "The object requested to lightmap is undefined" title:"Error" 
  	)
  	--BM_CLICK Message from MSDN
  
  	--Simulates the user clicking a button. This message causes 
  	--the button to receive the WM_LBUTTONDOWN and WM_LBUTTONUP 
  	--messages, and the button's parent window to receive a BN_CLICKED 
  	--notification message.
  
  	--Syntax
  
  	--To send this message, call the SendMessage function as follows.
  
  	--lResult = SendMessage( 		// returns LRESULT in lResult
  	--	(HWND) hWndControl, 		// handle to destination control
  	--	(UINT) BM_CLICK, 			// message ID
  	--	(WPARAM) wParam, 			// = 0; not used, must be zero
  	--	(LPARAM) lParam 			// = 0; not used, must be zero
  
  
  
  	--Open Render To Texture Dialog
  	macros.run "Render" "BakeDialog"
  	--Retrieve Handle of HWND of Render To Texture Dialog
  	rtt = windows.getChildHWND 0 "Render To Texture" parent:#Max
  	if rtt==undefined do
  		messageBox "The Render To Texture Window was not Found" title:"Error"
  	--Retrieve Handle to the add... button in the rtt interface
  	bAdd = windows.getChildHWND rtt [1] "Add..."
  	if bAdd==undefined do
  		messageBox "The add button in the rtt window was not found" title:"Error"
  	--Send a message "faking" that the user has clicked on it.
  	windows.sendMessage bAdd[1] BM_CLICK 1 0
  )
  renderLightmap selection[1] "C:\	estlightmap.png"
   

However, after the last line in renderLightmap(), I expect the add texture elements rollout to pop up like it usually does when the add button is clicked. But nothing happens, no error message box. I must be missing something here

3 Replies

You could try sending the LBUTTONDOWN and WM_LBUTTONUP messages manually:

local WM_LBUTTONDOWN = 0x201
local WM_LBUTTONUP = 0x202
...
windows.sendMessage bAdd[1] WM_LBUTTONDOWN 0 0
windows.sendMessage bAdd[1] WM_LBUTTONUP 0 0

Hope that helps,
Martijn

Surprisingly, it worked! Thanks so much.

Does anyone know if the Add Texture Elements rollout uses a standard windows Listbox?

EDIT: This is very strange. It seems that after I click on the Add button, the script automatically stops execution until the Add Elements Window is closed. Huh? Does anyone know how to bypass this?

Here’s the updated script. If you run it, you will notice it only prints when the add elements window is closed.

Perhaps I should write a stand-alone program in C using the windows api functions to do the same thing? 3ds Max wouldn’t be able to stop my application from executing.