Notifications
Clear all

[Closed] Set photometric light preset via maxscript?

Add this line to your ‘script as string’ to pass hWnd value as IntPtr:


	str += "hWnd = dotnetobject \"IntPtr\" hWnd
"


NOTE: that is to avoid the thrown error, no to make it work
NOTE2: sorry, forget about it

Ok, so I’ve discovered that if I add opening and closing parentheses to the output string, it does not work, i.e. this works:

select $TPhotometricLight001
maxC = windows.getChildrenHWND #max
hWnd = for i = 1 to maxC.count where maxC[i][5] == "Intensity/Color/Attenuation" do (exit with maxC[i+5][1])
hWnd = dotnetobject "IntPtr" hWnd
ComboBoxOps.SetCurrentSel hWnd 6
select s

but this does not:

(
select $TPhotometricLight001
maxC = windows.getChildrenHWND #max
hWnd = for i = 1 to maxC.count where maxC[i][5] == "Intensity/Color/Attenuation" do (exit with maxC[i+5][1])
hWnd = dotnetobject "IntPtr" hWnd
ComboBoxOps.SetCurrentSel hWnd 6
select s
)

So I’m assuming this is a situation in which some internal action that Max normally performs on its own is being skipped when the statements are run as a block.

i can’t try the code because there is no max around, but i guess that the code in block changes preset selection but doesn’t update. is it true?

No, it doesn’t even change the preset selection. Also, it’s not failing because of the selection change immediately after (one of my first thoughts), since even if I leave that out it doesn’t work.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

you have to set the light as a modified object first… and probably force to redraw modifier panel.

I think I would know how to do that using the SDK, but not with Maxscript (which is exactly the opposite of my usual situation).

When you say “set the light as a modified object”, I assume you are talking about invalidating it. Is that something that would be handled with a callback, is there some function I’m not aware of that will do that, does it need to be done as part of the assembly…?

As for forcing the panel to redraw, that seems simpler and I’m sure I’ve done something similar before, but I can’t seem to find the exact thing I am looking for in the documentation.

(
	delete objects
	light = Free_Light()
	max modify mode
	modpanel.setcurrentobject light
	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) 8
)

Okay, that gets me closer, the only issue now is that I want the selection to return to the control object after the change has been made.

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
		)
	)
)

and where is the problem to select previous back?

i don’t understand yours setup. what node do you add the custom attribute? why the attribute in a modifiers list?

Page 4 / 6