ScriptSpot

Forum topic · General Scripting

SME selection Callbacks

By drunkenmaster · 2022-02-15

Description

Hello, I have a question.

Is there a way to register user selection changes in SME.
For example I have two material nodes in SME view and want to execute some function when selection is changed.

For viewport selection changes I use this:

fn Subscribe = (callbacks.addScript #selectionSetChanged "MyRollout.VPSlection()" id:#VPSelectionID)

I want to do same thing but not in a viewport but in SME editor:

fn Subscribe = (callbacks.addScript #SMEselectionSetChanged "SMESlection()" id:#SMESelectionID)
fn UnSubscribe =( callbacks.removeScripts id:#SMESelectionID)
	
fn SMESelection = (Print "Slection changed")

Subscribe()
---UnSubscribe()

I know there is no callback type: SMEselectionSetChanged it's just examle what I'm looking for, but can I create calbacks like this/similar, or this is not posable at all ?

If not, I'm thinking maybe I can register left mouse click in SME. And execute function on mouse click somehow ?

Basically I want to get selected material node properties on user selection change without need to add some update button in UI (real time update).

I would appreciate if someone could help or point out to the right direction.
Thank You.

Comments (5)

Solution

drunkenmaster · 2022-03-03

It took very long to approve my post, so I've already solved the problem.

Here is solution if someone is interested:


fn getWindowClass =
	(
		local source  = "using System;
"
		source += "using System.Runtime.InteropServices;
"
		source += "public class Window
"
		source += "{
"
		source += "	[DllImport(\"user32.dll\")]
"
		source += "	public static extern IntPtr GetForegroundWindow();
"
		source += "}
"

		local csharpProvider = dotNetObject "Microsoft.CSharp.CSharpCodeProvider"
		local compilerParams = dotNetObject "System.CodeDom.Compiler.CompilerParameters"
		compilerParams.GenerateInMemory = true
		compilerParams.ReferencedAssemblies.Add "System.dll"
		local compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
		compilerResults.CompiledAssembly.CreateInstance "Window"
	)
	if NOT isKindOf ::window dotNetObject do window = getWindowClass()
)

try destroyDialog ::MyRollout catch()

---Create rollout "MyRollout" with two clock elements
---Then check if Dialog is in focus

-----GET_ FOCUS-----

local prevFocus = true, currFocus = true
	


  	on clock tick do
  	(
		currFocus = MyRollout.hwnd == (window.getForegroundWindow())
	if prevFocus != currFocus do clock2.active = if currFocus then false else true
		prevFocus = currFocus
			
		
  	)
--Then on second clock element (clock2) event exacute fuction to update values, do something you need

	on clock2 tick do
  	(
        ---Update values..
        ---Do Something..
        )

This prevents UI lockdown (It happens if you use one clock element and update UI on tick nonstop), because it updates just when UI is out of focus.
Using this metod you can interact with UI, for example enter values in texbox, spiners etc.

drunkenmaster · 2022-03-03

Thank you. I will check it out.

WindowShopper Not working

drunkenmaster · 2022-03-07

WindowShopper tool is not working for me geting error then trying to run it. Maybe it's not not supported on new max versions ? Are you using it ? Works for you ?

.

jahman · 2022-03-07

No, I don't use it. It is just a an opensource example of window subclassing.
Maybe it is max version or AD security tools blocking it, hard to tell.