ScriptSpot home

Forum topic · General Scripting

uiAccessor.getWindowText hwnd not working

By 3dwannab · 2017-07-18

Description

Hi, I'm trying two methods to press the default buttons of the 'V-Ray warning' dialog but neither are working.

If I evaluate

uiAccessor.getWindowText (dialogMonitorOps.getWindowHandle())

it returns

undefined

I know I can use this (But, that doesn't have a false switch):

setVRaySilentMode()

It's just, I need to get this to work with other scripts I've been working on, not just the V-Ray warning dialog. I've not gotten this to work for a while now and I'm nearly sure that it's something to do with my system.

Here's the two methods I've tried:


/* METHOD 1 */
clearlistener()
dialogMonitorOps.unRegisterNotification id:#VrayButtonYes
fn DiaMonOps_CloseVray = (
	local hwnd = dialogMonitorOps.getWindowHandle()
	local hwndChild = UIAccessor.GetChildWindows hwnd
	for i in hwndChild where uiAccessor.getWindowText i == "V-Ray warning" do
	(
		--   		uiAccessor.pressButtonByName hwnd "&Yes"
		uiAccessor.pressDefaultButton()
		)
	true
	)
dialogMonitorOps.enabled = true
dialogMonitorOps.interactive = false
dialogMonitorOps.registerNotification DiaMonOps_CloseVray id:#VrayButtonYes


/* METHOD 2 */
clearlistener()
dialogMonitorOps.unRegisterNotification id:#VrayButtonYes
fn DiaMonOps_CloseVray = (
	local hwnd = dialogMonitorOps.getWindowHandle()
	if uiAccessor.getWindowText hwnd == "V-Ray warning" do
	(
		--   		uiAccessor.pressButtonByName hwnd "&Yes"
		uiAccessor.pressDefaultButton()
		)
	true
	)
dialogMonitorOps.enabled = true
dialogMonitorOps.interactive = false
dialogMonitorOps.registerNotification DiaMonOps_CloseVray id:#VrayButtonYes

-- setVRaySilentMode()
Comments (6)
Panteleev Sergey

You can use Spy++ to determine parent of this message window and all the other info you may need.
btw. Any idea of how to get this warning window? Curious to test it myself.

Reply to Panteleev Sergey
pixamoon

`

probably is not linked to max window

try this:



try(destroyDialog ::textDialog)catch()

rollout textDialog "" width:100 height:20 (
	
	timer tm1 interval:500 active:true
	
	
	on tm1 tick do (
		for o in UIAccessor.GetChildWindows 0 where (t = UIAccessor.GetWindowText o) != undefined and tolower t == "v-ray warning" do (
			print "Found in method 1"
			print t
			UIAccessor.CloseDialog o
		)
		
	)
	
)

createDialog textDialog
Reply to pixamoon
3dwannab

Yeah, that worked. Thanks.

But I'm finding it hard to understand why the function is not firing using:

DialogMonitorOPS.RegisterNotification DiaMonOps_CloseVray id:#VrayButtonYes

It seems that 'DialogMonitorOPS.RegisterNotification' function method is not working for me because the function is not fired every time a dialog pops up.

Sooooo..., I found the problem!!

From this thread, I found out that startup scripts could be the culprit.

https://forums.autodesk.com/t5/3ds-max-programming/maxscript-dialogmonit…

I managed to find that it was a startup script in the user startup folder. Needless to say, it was one that I wrote. I've yet to find the culprit part but just glad I've found the issue.

Now to fix it!

Thanks P and sorry for wasting your time ;)

The warning window is created after opening an old version of a vray file in a newer install.

It's the one where it asks you, yes to update or no to render as was.
You cannot close this dialog via the Ops method.

PS. It was a startup script of my own that was hijacking the system and preventing it from firing. Yet to find the part of the script which caused the problem.

pixamoon

`

Hi, try with print to see what is exact window title

try to use also findString title "v-ray" or findString title "v-ray warning"


	fn DiaMonOps_CloseVray = try(
		local	hwnd = DialogMonitorOPS.GetWindowHandle()
		local title = UIAccessor.GetWindowText hwnd
		
		print title
		
		if title != undefined and (toLower title == "v-ray warning" or findstring (toLower title) "v-ray" != undefined) then
			uiAccessor.pressDefaultButton()
		
		true
		
	)catch()
	
	DialogMonitorOPS.unRegisterNotification id:#VrayButtonYes
	DialogMonitorOPS.RegisterNotification DiaMonOps_CloseVray id:#VrayButtonYes
	DialogMonitorOPS.Enabled = true
Reply to pixamoon
3dwannab

Thanks.. This sucks! That doesn't work. It's like it's not firing the function.

What does this return for you?

DialogMonitorOPS.GetWindowHandle()

I get

0P

I've checked the list of active OPS and it displays the one you gave, so somethings not quite right. My fresh install of 2017 is the same.

DialogMonitorOPS.ShowNotification()
--> id:#VrayButtonYes   function: DiaMonOps_CloseVray()