This is my test setup:
-- (ComboBoxOpsAssembly code)
ca = attributes "ca" (
parameters params rollout:RO (
lt type:#node
preset type:#integer ui:spn_preset default:2
)
rollout RO "" (
local s
spinner spn_preset range:[0,21,2] type:#integer
on RO open do (
s = (refs.dependentNodes (custAttributes.getOwner this))[1]
holder = s.modifiers["ca"]
)
fn changePreset val = (
max modify mode
modpanel.setcurrentobject lt
redrawviews()
h = windows.getchildhwnd #max "Command Panel"
c = windows.getchildhwnd h[1] "Color"
c = uiaccessor.getnextwindow c[1]
c = uiaccessor.getnextwindow c
hwnd = uiaccessor.getnextwindow c
ComboBoxOps.SetCurrentSel (dotnetobject "System.IntPtr" hwnd) val
--select s -- CODE WORKS WITH THIS LINE DISABLED, BUT I NEED TO RETURN TO THE CONTROL OBJECT
)
on spn_preset changed val do (
clearListener()
changePreset val
)
)
)
-- Create scene
---------------
delete objects
teapot segments:8
plane length:100 width:100
s = geoSphere()
s.pos = [0, 0, 100]
tgt = targetObject()
lt = Target_Light target:tgt intensity:15000
lt.pos = [100, -100, 100]
holder = emptyModifier name:"holder"
custAttributes.add holder ca #unique
holder.lt = lt
addModifier s holder
select s
Well I have to put this aside for a while, but it would be great if Denis or anyone else could solve the last remaining problem I’m having by the time I’m able to come back to it…
I have tried many things without success.
Everytime I change something to the ligth properties or exit the modify panel or select another object, or… by software, the combobox returns to its original value.
Sorry I can’t help.
There are still some ui flickering, but this seems to work from Max 2014 to 2017, and there is no need to compile any assembly:
(
ca = attributes "ca"
(
parameters params rollout:RO
(
lt type:#node
preset type:#integer ui:spn_preset default:1
)
rollout RO ""
(
local s
spinner spn_preset range:[0,20,1] type:#integer
on RO open do
(
s = (refs.dependentNodes (custAttributes.getOwner this))[1]
holder = s.modifiers["ca"]
)
[B] fn SetColorPreset presetIdx =
(
with redraw off with undo off
(
WM_SETREDRAW = 11
WM_COMMAND = 273
CB_SETCURSEL = 334
CBN_SELCHANGE = 1
WPARAM = 65740
cmdPanel = windows.getchildhwnd #max "Command Panel"
windows.sendmessage cmdPanel[1] WM_SETREDRAW 0 0
select lt
controls = windows.getchildrenhwnd #max
ctrlName = "Intensity/Color/Attenuation"
if (maxVersion())[1] >= 19000 do ctrlName = "MaxSDK::QMaxLegacyRollup " + ctrlName
hwnd = for i = 1 to controls.count where controls[i][5] == ctrlName do exit with controls[i+5][1]
parent = windows.getParentHWND hwnd
windows.sendmessage hwnd CB_SETCURSEL presetIdx 0
windows.sendmessage parent WM_COMMAND WPARAM hwnd
windows.sendmessage cmdPanel[1] WM_SETREDRAW 1 0
select s
)
)[/B]
on spn_preset changed val do SetColorPreset val
)
)
gc()
delete objects
teapot segments:8 wirecolor:gray
plane length:100 width:100 wirecolor:gray
s = geosphere pos:[0,0,100] wirecolor:red isselected:on
lt = target_light pos:[100,-100,100] target:(targetobject()) intensity:15000
holder = emptyModifier name:"holder"
custattributes.add holder ca #unique
holder.lt = lt
addModifier s holder
)
The light color (shown in the viewport) does not automatically update for me in all Max versions. In Max 2014 it seems like a bug in the light itself.
You can force to use the current color temp by adding this line after (or before) the “select s” line in the SetColorPreset function.
lt.useKelvin = off -- Update viewport light color (Max 2014 ?)
This one works from Max 2011 to 2017. The UI flickering issue is somehow “solved”, except for Max 2017 where there is still some redrawing.
The spinner redrawing can be improved to avoid using the “setKeyBrackets” workaround but I don’t see any problem using it.
Enjoy!
(
ca = attributes "ca"
(
parameters params rollout:RO
(
lt type:#node
preset type:#integer ui:spn_preset default:1
)
rollout RO ""
(
local s
spinner spn_preset range:[0,20,1] type:#integer
on RO open do
(
s = (refs.dependentNodes (custAttributes.getOwner this))[1]
holder = s.modifiers["ca"]
)
fn SetColorPreset presetIdx =
(
with redraw off with undo off
(
WM_SETREDRAW = 11
WM_COMMAND = 273
CB_SETCURSEL = 334
CBN_SELCHANGE = 1
WPARAM = 65740
cmdPanel = windows.getchildhwnd #max "Command Panel"
windows.sendmessage cmdPanel[1] WM_SETREDRAW 0 0
select lt
controls = windows.getchildrenhwnd #max
ctrlName = "Intensity/Color/Attenuation"
if (maxVersion())[1] >= 19000 do ctrlName = "MaxSDK::QMaxLegacyRollup " + ctrlName
local hwnd, parent
for i = 1 to controls.count where controls[i][5] == ctrlName do
(
hwnd = controls[i+5][1]
parent = controls[i+1][1]
)
windows.sendmessage hwnd CB_SETCURSEL presetIdx 0
windows.sendmessage parent WM_COMMAND WPARAM hwnd
select s
lt.useKelvin = off -- Update viewport light color (Max 2014 ?)
windows.sendmessage cmdPanel[1] WM_SETREDRAW 1 0
)
)
on spn_preset changed val inSpin do
(
SetColorPreset val
WM_SETFOCUS = 7
if not inSpin do windows.sendmessage RO.controls[1].hwnd[3] WM_SETFOCUS 1 0
spn_preset.setKeyBrackets = true
spn_preset.setKeyBrackets = false
)
)
)
gc()
delete objects
teapot segments:8 wirecolor:gray
plane length:100 width:100 wirecolor:gray
s = geosphere pos:[0,0,100] wirecolor:red isselected:on
lt = target_light pos:[100,-100,100] target:(targetobject()) intensity:15000
holder = emptyModifier name:"holder"
custattributes.add holder ca #unique
holder.lt = lt
addModifier s holder
)
Okay, things have been crazy, but I finally got a chance to open this back up and take a look at it.
The code works great save for one problem: it seems to completely nuke Max’s undo system. Once the spinner has been used, the undo option is disabled for all future actions in the same session. Any idea why that would be the case?
EDIT:
Okay wait, never mind about the “all future actions in the same session”. It seems that creating a new object will reset the undo system. Still not totally sure why this is happening though.
If you just select and move any object, the undo seems to start working again too.
If you change the “on change” event handler to “on entered”, the problem seems to be fixed.
However, every change to the spinner creates an undo entry, which does undo/redo, but the light is not updated.
Overall, this is a very ugly hack so I have the felling every little thing you fix may break other little things.
Yeah now that you pointed it out that’s true. Not sure why selections don’t do the same, but oh well. It’s still a fantastic bit of code