Simple Python scripting problem(s)


#1

Hi all guys!
I have been looking for hours how to perform a very simple script in Python for 3DS Max (v2017), but the APIs are terrible - to say the least.

What I need to do is simply tell to 3ds Max to change a Rendering Effect Attribute when a certain scene camera is selected - or the view is switched to that camera.

I will write you down the script in pseudo code so you can - hopefully - better understand the topic:

camera_1 = MaxPlus.Factory.SelectCameraObject(“36x24_MoreDof”)
camera name is 36x24_MoreDof

camera_2 = MaxPlus.Factory.SelectCameraObject(“36x24_LessDof”)
camera name is 36x24_LessDof

effect1 = RenderingTab.EnvironmentAndEffects.Effects.Attribute1
effect2 = RenderingTab.EnvironmentAndEffects.Effects.Attribute2

effect1.active = False
effect2.active = False

while True:
if camera_1.isSelected == True:
effect1.active = True
effect2.active = False
elif camera_2.isSelected == True:
effect1.active = False
effect2.active = True

I hope it is clear enough… Do you have any idea how to translate this in actual Python code for 3DS Max?

Thanks you all in advance,

Riccardo

ps. If you know how to do it in MAX script, it is still welcome! :smiley:


#2

Hi there!

I have been able to write the script in MAX Script, checking in the APIs and using the script Listener.

this is how the main script looks like:

if $36x24_MoreDof.isSelected == true then setActive(getEffect 1) true else setActive(getEffect 1) false

if $36x24_LessDof.isSelected == true then setActive(getEffect 2) true else setActive(getEffect 2) false

When I select the first camera, it turns on a specific Bokeh lens effect . If I select the second camera, it turns on a different Bokeh effect.

Now, I need to make this script constantly running, listening to the events changes and updating the outputs every time I select or deselect the camera/s.
Something like a callback function, or a “while True do…” (which actually generate an infinite loops and fucks up Max)

Any idea how to do so?

Thanks all!


#3

…done this too:

when select $36x24_MoreDof changes do if $36x24_MoreDof.isSelected == true then setActive(getEffect 1) true else setActive(getEffect 1) false

when select $36x24_LessDof changes do if $36x24_LessDof.isSelected == true then setActive(getEffect 2) true else setActive(getEffect 2) false

Next polishing would be, much better, to make these changes happening also when the viewport view is swapped to the two Cameras.

Any suggestion is more then welcome! : )


#4
when select cameras changes id:#when_camera_changed cam do 
(
	case cam.name of
	(
		#'36x24_MoreDof': setActive (getEffect 1) cam.isSelected
		#'36x24_LessDof': setActive (getEffect 2) cam.isSelected
	)
)

or

when select cameras changes id:#when_camera_changed cam do 
(
	_effect = case cam.name of
	(
		#'36x24_MoreDof': getEffect 1
		#'36x24_LessDof': getEffect 2
	)
	if iskindof _effect renderEffect do setActive _effect cam.isSelected
)

#5

Thanks man!

I’ll give it a try asap.

For the moment I solved the issue creating a button that runs the script every time I need, and changes the lens effect based on viewport.getCamera() output.
And works pretty well!