Notifications
Clear all

[Closed] Memory issue with getvert $.mesh

My noob scripting skills have come to a grinding halt!

What I’m trying to do is export all of the vertex point positions for a deforming object to
a file sequence.

So far I’ve gotten it to work on huge objects (1mill vertices) for one frame, as soon as I try to create a loop and export the object as a sequence I come to a halt pretty quickly.

All I get is a “Unknown system exception” error and it points to the “pos = getvert $.mesh i” line and then I get a “max has run out of memory error”.

This is what I get with a object with 720 vertices but it works with a small one with 42.

I’ve tried enableing undo off and with redraw off to get more memory but its still crashing even with the objects that have 720 vertices!

Are there any do’s and dont’s I need to know about file handling and the mesh getvert functions?

I’ll attach a copy of the script in its current state if someone cares to take a look!

Thanks!

-theo

6 Replies
3 Replies
(@bobo)
Joined: 1 year ago

Posts: 0

Everytime you call $.mesh, a NEW TriMesh value containing all vertices, faces, edge vis flags, material IDs etc. is allocated in memory. So for 720 vertices, it is equivalent to creating 720 copies of the mesh in memory. Also, MAXScript has only 7.5 MB of Heap Memory allocated by default, so it will run out of memory much earlier than Max itself – if you would copy a mesh 720 times in the scene, it would still eat a lot of memory, but it doesn’t have as much limitations… You can increase the MAXScript Memory in the Customize>Preferemces>MAXScript tab to avoid memory crashes when collecting a lot of values in arrays and so on.

But back to your problem.
The correct way to do this is to say:

theMesh = $.mesh --creates a TriMesh value in memory with a variable pointing at it
 for v = 1 to theMesh.numverts do 
 (
 theVert = getVert theMesh v  
 --do some more stuff here
 )
 delete theMesh --delete the value, marking the variable as unused for the Garbage Collector

If you want the mesh in world space after all Space Warps, you can use

theMesh = snapshotAsMesh $ --creates a TriMesh value in memory 
 for v = 1 to theMesh.numverts do 
 (
 theVert = getVert theMesh v  
 --do some more stuff here
 )
 delete theMesh --delete the value, marking the variable as unused for the GC
(@gryps81)
Joined: 1 year ago

Posts: 0

Hi

Could you explain me why mesh is deleting form max file when i call “delete theMesh”?
Its happend some times, and not every mesh is deleting.

thanks
Gryps

(@bobo)
Joined: 1 year ago

Posts: 0

My bad, deleting theMesh when using $.mesh where $ is an Editable_Mesh object actually deletes the mesh from the base object. You might want to use ‘copy $.mesh’ to create an independent copy of the TriMesh. It does NOT delete if your object is not an Editable_Mesh or has modifiers on top, as the TriMesh is implicitly copied.

Bobo, you are my hero and I owe you a beer! Works like a charm!

-theo

Hi,

I have a problem:

in my code I use:
theMesh = node.mesh
and when I deleting theMesh, some mesh are deleting form max file. This situatuion not occurs in every file.
Anybody have idea what is wrong

Thanks for answers
Paweł

Thank you very much, I check yours suggestions.

Thanks a lot
Paweł