From\To selected objects - Get\Assign material

The subject must work with Slate editor via shortcut.
Could anybody help please?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
1rv's picture

No, setting up shortcuts to

No, setting up shortcuts to "Assign Mat to Selection (SME)" and "pick mat from object" (ME) do nothing on my end at least.
The only thing that works for me is "Get material" form K-studio but it doesn't work with SME's main window

jahman's picture
1rv's picture

try yourself- pick pick

from my experience pick pick material via shortcut with\without toggle override does nothing. "assign material" kinda works, but second shortcut (to turn keyboard toggle ON) needed to which is dumb

jahman's picture

.

from my experience pick pick material via shortcut with\without toggle override does nothing
SME window must be in focus/active (being open isn't enough) in order for any action to work via shortcut.
Shortcuts are binded to a certain context and if the window isnt active they of course wont work...

1rv's picture

Try to assign some shortcut

Try to assign some shortcut to "pick material from selection" (say Alt+U) and see *yourself* - it does nothing in SME. No matter where's the focus SME main window\sample slots\viewport keyboard toggle on\off

jahman's picture

.

I have 'Get from Selected' & 'Assign material to selection' in SME. Both working.
But there's no 'pick material from selection', basic material editor has 'Pick material from Object'. Guess you're talking about this one? Yes, can confirm that it doesn't work, niether by shortcut nor by calling actionMan.executeAction 2 "1101" directly

macroScript PickMtlFromObj
category:"Medit_Custom"
tooltip:"Pick material from object"
(
	/*
	-- #1 custom solution
	fn HasMtl n = n.material != undefined
 
	local obj = pickObject filter:HasMtl
	if isValidNode obj and obj.material != undefined do
	(
		medit.PutMtlToMtlEditor obj.material (medit.GetActiveMtlSlot())
	)
	*/
 
	-- #2 press button programmatically
	if MatEditor.isOpen() do 
  (
	local hwnd = for w in uiaccessor.getpopupdialogs() where filenameFromPath (UIAccessor.GetWindowDllFileName w) == "res1.dll" collect w
	if hwnd.count > 0 do
	(	
		hwnd = hwnd[1]
		done = false
 
		for w in windows.getChildrenHWND hwnd while not done where w[4] == "CustButton" and UIAccessor.GetWindowResourceID w[1] == 1101 do
		(
			done = true
			UIAccessor.PressButton w[1]		
		)
	)
  )
 
)

I'm pretty sure there're tons of script similar to this one already written and posted here on scriptspot. I'd choose one which works for both sme and basic mtledit

upd
and of course, when the workaround is found the correct solution comes

(
    MatEditor.open() -- force basic medit in to focus, otherwise it won't work
    actionMan.executeAction 2 "1101"
)
1rv's picture

Well "Get from Selected" is

Well "Get from Selected" is something in the right direction - thank you. Though the demand to stay focused on SME is not so user friendly, I need something working from the viewport.
Forgive my ignorance, but what am I supposed to do with the code in "upd" part?

>>I'm pretty sure there're tons of script similar to this one already written and posted here on scriptspot. I'd choose one which works for both sme and basic mtledit

I haven't found one, hence I posted here.

jahman's picture

.

well, here's a quick 'pick mtl from scene for basic&sme'. not tested

macroScript PickMaterialFromScene
category:"Jahman"
tooltip:"Pick material from scene"
(
	if MatEditor.mode == #basic then
	(	
		MatEditor.open() -- force basic medit in to focus, otherwise it won't work
		actionMan.executeAction 2 "1101"
	)
	else
	(
		if not SME.IsOpen() do SME.Open()
 
		fn GetSMEWindowHandle = 
		(	
			max_hwnd = windows.getMAXHWND()
			for m in windows.getChildrenHWND 0 where m[4] == "NodeJoeMainWindow" and m[6] == max_hwnd do exit with m[1]		
		)
 
		local sme_hwnd = GetSMEWindowHandle()
 
		windows.sendMessage sme_hwnd 0x111 41005 0
 
	)
)	
1rv's picture

Amazing, thanks a ton Jahman

Amazing, thanks a ton Jahman :) works so far so good
Is the eyedropper click inevitable? Can't the material be sent straight to SME?

jahman's picture

.


Is the eyedropper click inevitable? Can't the material be sent straight to SME?

That's even simpler. The only difference with the original sme action that this one doesn't require sme to be focused. And keep in mind that it gets all materials from selected nodes

macroScript SmePickMaterialFromSelection
category:"Jahman"
tooltip:"SME get material from selection"
(
	if SME.IsOpen() do
	(
		(SME.GetMainframe()).setfocus()
		if SME.GetNumViews() == 0 do SME.CreateView "View1"
		actionMan.executeAction 369891408 "55581" -- Get from Selected
	)	
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.