Reputation: 21
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.
I can't even get how to select an existing object in the scene.. Plus I do not understand if I should use pymxs wrapper or MaxPlus.
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
Upvotes: 2
Views: 4603
Reputation: 986
Below is python script to use as a guide for your request.
Basically, I recommend thinking of yourself as a MaxScript programmer who uses Python for the language benefits. To access the 3ds Max scene, go through MaxScript (via PyMXS). Then you employ Python's strengths for string processing and data management (dictionaries!). Use MaxPlus when necessary for certain lower-level SDK access.
The script below fetches an object by name, fetches a render effect by index, and enables/disables the render effect according to the object selection:
import pymxs
mxs = pymxs.runtime
object_1 = mxs.getNodeByName( "Camera001" )
effect_1 = mxs.getEffect(1)
effect_1.camera
mxs.setActive(effect_1, mxs.false)
if object_1.isSelected:
mxs.setActive(effect_1, mxs.true)
Hope this helps!
Upvotes: 3