Maxplus multi-threading

#1

Does anyone ever achieve to do something like this?
Because my Max is continuously crashing when I try to do multi-threading

def create():
    obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Cylinder)
    obj.ParameterBlock.Radius.Value = 10.0
    obj.ParameterBlock.Height.Value = 30.0
    node = MaxPlus.Factory.CreateNode(obj)


start = time.clock()
locker = threading.Lock()
evt = threading.Event()
t1 = threading.Thread(target=create)
t2 = threading.Thread(target=create)
t3 = threading.Thread(target=create)
t1.start()
t2.start()
t3.start()
end = time.clock()
print "process completed in " + str(end - start)
#2

Threading isn’t allowed. From the MaxScript / Python docs:

NOTE: Python scripts run in MAXScript are not thread-safe. Python commands are always executed in the main 3ds Max thread. You should not attempt to spawn separate threads in your scripts (for example, by using the Python threading module).

#3

You can use worker threads to read your scene data and work with big groups of data using dotNet in maxscript. Creating objects will cause random crashes.
You can safely manipulate python data ( non max objects ) in python threads. Calling a pymxs object from a python thread will throw a runtime error.
There is a threading example for creating objects using locks in the python examples and whilst it is functional, it isn’t true asynchronous threading and the performance gain very swiftly disappears as you are having to gain control of the GIL (Google python GIL ) constantly to create an object.
Threading directly in max is somewhat of a dead end without a lot of effort and even then the uses are very limited.
My advice would be to learn the SDK instead. It may not be as exciting as threading but the effort to performance boost is a much more rewarding ratio.

#4

Thanks all for the reply.
Yes I should probably go with your solution , ideally I would like to make some plugins around max containers
For now batch containers merge/unmerge is pretty heavy.
Do you is there any way to improve this, using the SDK?

#5

Ah apologies, I was not aware of your user case.
I am doubtful that the SDK will improve a merge operation. The maxscript function will be a direct wrapper of the c++ one, so the operation itself is likely slow. The time taken to merge will be completely dependent on the size of the container.
The biggest speed boost you will get from the SDK is for loops and data manipulation rather than single scene operations.