ScriptSpot

Forum topic · General Scripting

Callback when SME is open and closed

By 3dwannab · 2016-09-11

Description

I've got the callback for when SME is open from MSX help and I've tried to reverse engineer it to work when it's closed.

I've never used dialogmonitorops or UIAccessor before so any help would be appreciated.

Code I've got so far:


clearlistener()
DialogMonitorOPS.unRegisterNotification id:#mxs_test_open
DialogMonitorOPS.unRegisterNotification id:#mxs_test_closed


fn SlateCallbackOpen = (
	clearlistener()
	h = dialogmonitorops.getwindowhandle() -- get current popup window

	if UIAccessor.GetWindowText h == "Slate Material Editor" then (
		print "Slate Material Editor is opened"
		print (UIAccessor.GetWindowClassName h)
		print (UIAccessor.GetWindowText h)
	)
	true
)

fn SlateCallbackClosed = (
	clearlistener()
	h = dialogmonitorops.getwindowhandle() -- get current popup window

	if UIAccessor.GetWindowText h != "Slate Material Editor" then (
		print "Slate Material Editor is closed"
		print (UIAccessor.GetWindowClassName h)
		print (UIAccessor.GetWindowText h)		
	)
	true
)

-- register dialog monitor callback notificition
dialogmonitorops.registernotification SlateCallbackOpen id:#mxs_test_open
dialogmonitorops.registernotification SlateCallbackClosed id:#mxs_test_closed

-- enable dialog monitor
dialogmonitorops.enabled = true
Comments (5)

3dwannab · 2016-09-13

Got this example now from the help file also..

(
sme.Open() --Open the SME
theParent = windows.getChildHWND 0 "Slate Material Editor" --get the HWND of the SME
rollout sme_toolbox_rollout "SME Toolbox"
(
	button btn_nextMap "UP One Level" width:150
	on btn_nextMap pressed do
	(
		theObj = sme.GetMtlInParamEditor() --get the node from the parameter panel
		if theObj != undefined do --if there is a valid node, get its dependents
		(
			local theDeps = for m in refs.dependents theObj where isKindOf m TextureMap or isKindOf m Material collect m
			if theDeps.count > 0 do sme.SetMtlInParamEditor theDeps[1]	--if there were any, select the first one	
		)
	)
)
createDialog sme_toolbox_rollout parent:theParent[1] --create a dialog as child of the SME
)

But still no moving with SME yet..

3dwannab · 2016-09-13

I think I've got a headache looking at this stuff.. I might ask over on some of the other MXS forums :)

`

pixamoon · 2016-09-13

I'm looking now into WindowShopper by Rotem Shiffman

it read messages of windows in real time and it uses "WndProc"

I'll try to get some function to read windows move only

`

pixamoon · 2016-09-13

oki,

here is it a small script to create callback for external window

it only prints out SME position but you will see general idea how it works

it's based on Window Shopper by Rotem Shiffman:
http://www.monotoneminimal.com/free-tools

take a look in attachment

remember to declare callback as global and release handle when you close your script


global msgSnooper
try(msgSnooper.releaseHandle())catch()

when callback is a global variable you can stop it also when script crash -> msgSnooper.releaseHandle()

ha, and also... with this callback messages you can read when SME is opened or closed :)

Attachments