[MAX]Change Handlers and When Constructs

hi all
what is the equivalent in python for this:
when transform $box001 changes do
???

There isn’t one.
You need to create a maxscript function that is globally accessible and then call it via pymxs.runtime

the day autodesk 3ds max will loose all of his clients , i will be a happy man.
Everything in this software is no sense

1 Like

That isn’t true, it makes perfect sense.
The when event handlers are a very maxscript-centric construct that do not really have an equivalent implementation in Python.
The only thing to do is create a wrapper utility function which is accessible to Python, which is 90% of all coding.
The fact that there is such a great level of access between maxscript and python is actually really amazing, one of the really great things AD have done for Max in recent years.

I still do not see how to do it without max script, there is no notification that is tiggered when a object move
MaxPlus.NotificationManager.Register(MaxPlus.NotificationCodes.PostNotifydependents, on_post_notify_dependents) The best one I found is this.
And I did not understand your point :

**The only thing to do is create a wrapper utility function which is accessible to Python, which is 90% of all coding**

Thanks anyway

I mean if I have to do this in a pythonic way, what should I do?

You are being too focused in your approach to finding a solution.
You cannot do it without maxscript as you are wanting to use a maxscript construct.
All you need to do is write a function in maxscript:

Global myMaxScriptCallbackFunction
Fn myMaxScriptCallbackFunction inObj =(
    when Transform inObj changes do (
        -- do something
        print(inObj.Name)
      )
)

Then call it from a python script:

from pymxs import runtime as mxRt

mxRt.myMaxScriptCallbackFunction(mxRt.Selection[0])

I cannot make it any clearer than that, if you can’t figure it out from this then nothing AD ever does will make it any easier.

My problem is not that I want to use this construct:
when Transform inObj changes do
My problem is that I cannot find a way to have any notification when an object is moved.
Autodesk made maxplus, .net, and pymxs and the only way to catch this callback is in max script.
I will do it in maxscript , because as you said is the only way, but the fact that a python wrapper luck of features it is not a problem on my side, but a problem on Autodesk side
I’m writing a tool that will you pyside and advanced features of python, I’m not an expert in 3dsmax,as I am a Maya user, but I have enough experience to know that mix two languages is not a good practice.
Autodesk force users to create dirty code and you are saying that this is normal.
Anyway my opinion on this elephant called 3dsmax will not change today, but I’m grateful to you anyway

Mixing two languages is bad practice?
Whoever told you that was clearly joking with you.
You know that python is written on top of c?
Loads of python modules have c backends. Which is exactly what the example I provided has done; wrapped features of one language to make them conveniently accessible by another language.
That’s mixing languages, and it is how programming works unless you are writing pure machine code.

Max and Maya both provide access to their native scripting languages via python to cover cases such as this. Maya just has a more mature api so a lot of the fringe cases will be covered by a wrapper function that someone had to write to give python access to a melscript exclusive feature.
No one is making you write dirty code, you are merely writing a simple wrapper function. If you are not sure what a wrapper function is, Google it.

Ultimately though, glad you were able to solve the problem and hopefully learn something in the process.

This is a never-ending discussion.
I don’t think that make evaluation of other script passed as a string is a good practice.
This as nothing to do with the fact the python is built on top of C
Good luck

1 Like

You aren’t evaluating a string, at least not how you are meaning it*, you are calling a function written in maxscript through a python api wrapping maxscript. That is what every single function in pymxs is doing! The only issue is that there isn’t an out of the box wrapped function for what you want to do. Thankfully you have been provided all the tools necessary to write your own one with very little effort.

*Just to point out that python evaluates strings to turn your human readable code saved in a .py file into bytecode in a .pyc file.
Your complete misunderstanding of how programming languages work is galling and unfortunately for you, what you think and what is true are two very separate and non related things.

I mean really, it is fine to not know how things work as no-one knows everything there is to know, but to refuse to accept a thing because it doesn’t fit with your preconceived notion of how said thing works is a very damaging mindset to have.

Sadly, I can’t make you think out of a mindset you have thought yourself into, so keep learning and hopefully you will eventually be able to appreciate the tools others have provided for you without blaming them for your own lack of knowledge.

1 Like

Now you made the point so clear,
Thanks Autodesk , for providing us so many tools with this perfect documentation.
Even the research function in 3dsmax is so perfect,they should spread their ,knowledge