SixSioux
SixSioux

Reputation: 21

3DS Max Python scripting

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

Answers (1)

MichaelsonBritt
MichaelsonBritt

Reputation: 986

Below is python script to use as a guide for your request.

  • PyMXS; my advice is to use this primarily. It wraps almost all of MaxScript (except for some exotic MaxScript syntax features). It has been continuously developed for decades, is robust, and offers a lot of helper functionality and simplifications compared to the 3ds Max SDK which it's build on.
  • MaxPlus; my advice is to use certain bits of this which aren't covered by PyMXS (for example the function MaxPlus.GetQMaxMainWindow() for creating a Qt-based UI), but don't use this as the primary tool in Python. It is newer, and while it might prove better for Python exposure of the 3ds Max SDK in the long term, you might prefer PyMXS for coverage and simplicity in the short term.

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

Related Questions