The subject must work with Slate editor via shortcut.
Could anybody help please?
Forum topic · Scripts Wanted
From\To selected objects - Get\Assign material
By 1rv · 2023-01-31
Description
Comments (22)
1rv · 2023-01-31
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 · 2023-01-31
try yourself- pick pick
1rv · 2023-01-31
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 · 2023-02-01
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 · 2023-02-01
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 · 2023-02-01
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 · 2023-02-02
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 · 2023-02-02
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 · 2023-02-02
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 · 2023-02-02
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
)
)
1rv · 2023-02-04
Works like a charm thank you so much Jahman, will definitely use it a hundred times per day.
Now may I kindly ask you to make "Select by active (SME) material" :) ?
.
jahman · 2023-02-04
should work
macroScript SelectNodesByMaterial
category:"Jahman"
tooltip:"SME select nodes by material"
(
fn GetSMESelection nodes:false =
(
local index = sme.activeView
local viewNode = sme.GetView index
local SME_Selection = #()
if index > 0 do
(
local tv = trackViewNodes[#sme][index]
for n = 1 to tv.numSubs do
(
local ref = tv[n].reference
local _node = viewNode.GetNodeByRef ref
if _node != undefined and _node.selected do append SME_Selection ( if nodes then #( ref, _node ) else ref )
)
)
SME_Selection
)
on execute do if SME.IsOpen() do
(
local nodes = #()
for m in GetSMESelection() do join nodes (refs.dependentNodes m)
select nodes
)
)
1rv · 2023-02-04
Made my day. Thanks a ton :)
.
jahman · 2023-02-04

1rv · 2023-02-04
I'd recommend to post them so it won't get buried in Wanted sub-forum,
Best
:D
jahman · 2023-02-04
Those who want something special should invest some of their time to google things up as I'm too lazy to test these scripts, upload 'em, make a description etc...
1rv · 2023-02-06
One tiny and hopefully :) final request: when user hits a dedicated shortcut, could the script open SME if its closed?
.
jahman · 2023-02-06
can't edit my prev posts, unfortunately
replace it with this:
on execute do
(
if not SME.IsOpen() do SME.Open()
local nodes = #()
for m in GetSMESelection() do join nodes (refs.dependentNodes m)
select nodes
)
I get:-- Syntax error: at ),
1rv · 2023-02-06
When SME is closed I get an error:
-- Syntax error: at ), expected
-- In line: )
After my lame edit the mcr looks like:
macroScript SmePickMaterialFromSelection
category:"Jahman"
tooltip:"SME get material from selection"
on execute do
(
if not SME.IsOpen() do SME.Open()
local nodes = #()
for m in GetSMESelection() do join nodes (refs.dependentNodes m)
select nodes
)
What to fix?
P.S. Still works fine if SME is open
.
jahman · 2023-02-06
Perfect mushas gracias :)
1rv · 2023-02-06
Perfect muchas gracias :)
Must be native command
.
jahman · 2023-01-31
isn't SME already have actions to get materials from selection and to assign mtls to selection?