Notifications
Clear all

[Closed] Setting viewport antialiasing through maxscript

and these are my d3d settings, it’s relevant maybe?

max 2009 has to have the ini file. it might be in another than max 2010 directory.

1 Reply
(@panayot)
Joined: 11 months ago

Posts: 0

Ok, I see your point.
Now i found d3dgfx.ini in my max2009 root folder, and doesFileExist() now return true.
Still cannot test this solution in my Max (for AAQuality), but good to know.
Glad to see too that my script fit well Nihat Dogan needs.

maybe it’s driver dependent…

I am able to switch wireframe AA on the fly in Max 2011 on a non-Quadro ( 9800GTX )
same on Max 2009 ( was wrong, so i edited the post )

don’t have 2010 installed to test…

Note:i have installed a quadro driver via. modified inf -file ( 275.89 )

here is my version that has to work for any max version (2009+) and any graphic card:


fn CircleAntialiasingQuality = 
(
	DialogMonitorOPS.unRegisterNotification id:#PreferenceWatcher

	local enabled = DialogMonitorOPS.enabled
	
	fn notification = 
	(
		hwnd = DialogMonitorOPS.GetWindowHandle()
		if (UIAccessor.isWindow hwnd) do case (UIAccessor.GetWindowText hwnd) of
		(
			"Preference Settings":
			(
				b = windows.getchildHWND hwnd "Configure Driver..."
				BM_CLICK	= 0x00F5
				windows.sendMessage b[1] BM_CLICK 0 0
				UIAccessor.PressDefaultButton()
			)
			"Configure Direct3D":
			(
				b = windows.getchildHWND hwnd "Antialiasing Quality:"
				c = UIAccessor.GetPrevWindow b[1]
				
				CB_GETCOUNT 	= 0x0146
				CB_GETCURSEL 	= 0x0147
				CB_SETCURSEL 	= 0x014E
				
				count = windows.sendMessage c CB_GETCOUNT 0 0
				current = windows.sendMessage c CB_GETCURSEL 0 0
				current = mod (current + 1) count
					
				windows.sendMessage c CB_SETCURSEL current 0
				
				format "Current AA Quality: %
" (UIAccessor.GetWindowText c)
				UIAccessor.PressDefaultButton()
			)
			"3ds Max": UIAccessor.PressDefaultButton()
		)
		true
	)
	DialogMonitorOPS.enabled = on
	DialogMonitorOPS.RegisterNotification notification id:#PreferenceWatcher
	max file preferences
	DialogMonitorOPS.unRegisterNotification id:#PreferenceWatcher
	DialogMonitorOPS.enabled = enabled
)
CircleAntialiasingQuality()

1 Reply
(@panayot)
Joined: 11 months ago

Posts: 0

Hi Denis, you have many years behind in programming and I was sure you’ll not resist and will dominate with some optimized code

Well, good to know about CB_GETCOUNT, thanks, but your code do not work in Max 2009.
After running the D3D-config dialog is closed, Pref.-dialog stay open, and the monitorOps notification stay active. Also to stop it I should type “DialogMonitorOPS.enabled=off” directly to the mini-listener because the callback auto close the floater Listener.

I have not time for tests now, I just suspect (before running the code) something unsafe in this line:

b = windows.getchildHWND hwnd "Antialiasing Quality:"

…and the log to the Listener confirm that ’cause it drops on the next line.
Here is the log:

CircleAntialiasingQuality()
-- Error occurred in notification(); filename: C:\Denis-code.ms; position: 628
-- Frame:
-- c: undefined
-- current: undefined
-- BM_CLICK: undefined
-- b: undefined
-- CB_SETCURSEL: undefined
-- count: undefined
-- CB_GETCURSEL: undefined
-- hWnd: 1510480
-- CB_GETCOUNT: undefined
-- Error occurred in notification(); filename: C:\Denis-code.ms; position: 628
-- Frame:
-- c: undefined
-- current: undefined
-- BM_CLICK: undefined
-- b: undefined
-- CB_SETCURSEL: undefined
-- count: undefined
-- CB_GETCURSEL: undefined
-- hWnd: 1576016
-- CB_GETCOUNT: undefined
-- Error occurred in notification(); filename: C:\Denis-code.ms; position: 628
-- Frame:
-- c: undefined
-- current: undefined
-- BM_CLICK: undefined
-- b: undefined
-- CB_SETCURSEL: undefined
-- count: undefined
-- CB_GETCURSEL: undefined
-- hWnd: 1641552
-- CB_GETCOUNT: undefined
-- called in CircleAntialiasingQuality(); filename: C:\Denis-code.ms; position: 1335
-- Frame:
-- enabled: false
-- notification: notification()
** system exception **
false

hm…
it works for 2010-2012. i didn’t test it in 2009. but you right i had to do it safer way…


   fn CircleAntialiasingQuality = 
 (
 	DialogMonitorOPS.unRegisterNotification id:#PreferenceWatcher
 
 	local enabled = DialogMonitorOPS.enabled
 	
 	fn notification = 
 	(
 		hwnd = DialogMonitorOPS.GetWindowHandle()
 		if (UIAccessor.isWindow hwnd) do case (UIAccessor.GetWindowText hwnd) of
 		(
 			"Preference Settings":
 			(
 				b = windows.getchildHWND hwnd "Configure Driver..."
 				BM_CLICK	= 0x00F5
 				windows.sendMessage b[1] BM_CLICK 0 0
 				UIAccessor.PressDefaultButton()
 			)
 			"Configure Direct3D":
 			(
 --				b = windows.getchildHWND hwnd "Antialiasing Quality:"
 --				c = UIAccessor.GetPrevWindow b[1]
 				
 				if (c = for c in windows.getchildrenHWND hwnd where c[4] == "ComboBox" do exit with c[1]) != ok do
 				(
 					CB_GETCOUNT 	= 0x0146
 					CB_GETCURSEL 	= 0x0147
 					CB_SETCURSEL 	= 0x014E
 					
 					count = windows.sendMessage c CB_GETCOUNT 0 0
 					current = windows.sendMessage c CB_GETCURSEL 0 0
 					current = mod (current + 1) count
 						
 					windows.sendMessage c CB_SETCURSEL current 0
 					
 					format "Current AA Quality: %
" (UIAccessor.GetWindowText c)
 				)
 				UIAccessor.PressDefaultButton()
 			)
 			"3ds Max": UIAccessor.PressDefaultButton()
 			  default: UIAccessor.PressDefaultButton() -- in case of OpenGL
 		)
 		true
 	)
 	DialogMonitorOPS.enabled = on
 	DialogMonitorOPS.RegisterNotification notification id:#PreferenceWatcher
 	max file preferences
 	DialogMonitorOPS.unRegisterNotification id:#PreferenceWatcher
 	DialogMonitorOPS.enabled = enabled
 )
 CircleAntialiasingQuality()
   

i’m searching the cobmobox the same way as you … and don’t see a better way.

but the really interesting thing is how to pop-up dialogs in hidden mode (or out of screen at least)

might be a start

HookHandle = SetWindowsHookEx( WH_CALLWNDPROC,
(HOOKPROC) Hooker,
(HINSTANCE)NULL,
(DWORD)GetCurrentThreadId() );

The hook is of type WH_CALLWNDPROC. This means that the hook gets all messages first, before the target window procedure(s) gets it. Therefore, custom processing can be made at this point, since we get a first crack at the message.

or another starting point that looks interesting…

http://msdn.microsoft.com/en-us/library/ms644977(v=VS.85).aspx

HCBT_CREATEWND

A window is about to be created. The system calls the hook procedure before sending the WM_CREATE or WM_NCCREATE message to the window. If the hook procedure returns a nonzero value, the system destroys the window; the CreateWindow function returns NULL, but the WM_DESTROY message is not sent to the window. If the hook procedure returns zero, the window is created normally.

At the time of the HCBT_CREATEWND notification, the window has been created, but its final size and position may not have been determined and its parent window may not have been established. It is possible to send messages to the newly created window, although it has not yet received WM_NCCREATE or WM_CREATE messages. It is also possible to change the position in the z-order of the newly created window by modifying the hwndInsertAfter member of the CBT_CREATEWND structure.

4 Replies
(@denist)
Joined: 11 months ago

Posts: 0

is it a joke?
certainly i played with window hooks… but i couldn’t find a right event to move a window just before it was drawn.

(@spacefrog)
Joined: 11 months ago

Posts: 0

Why should it be a joke ? i just posted some things i would start experimenting with…

(@denist)
Joined: 11 months ago

Posts: 0

sorry. i meant no harm. the sentence “[window hooks] might be a start” sounds like a joke for be, because it’s more like i should stop playing with hooks and look for other solution. or maybe i missed something and have to take a new and different view of this task.

(@spacefrog)
Joined: 11 months ago

Posts: 0

no problem – now i understand your post:
If you are already fighting your battles with hooks my suggestion might indeed look like a joke to you

… double-posted

yes, i read it. the thing is – i’m catching the creation event, re-position the created window, but developers move the window using its shown event. so they move the window away from my hacked position after the window was created.
there is a way to suspend the window move… but i didn’t have a time to play with this idea.

I was wondering about that too.

Denis,
1. Can I toggle just between 2 AA values instead of cycling the values? e.g. 0 and 8
2. How can I re-use the changed AA value in the script? Because I also want to change gamma depending on AA state in the same script.
if AA value is set to 0 gamma should be turned on

IDisplayGamma.colorCorrectionMode = #gamma
  if AA value is set to something else other than 0 gamma should be turned off
IDisplayGamma.colorCorrectionMode = #none
Page 2 / 3