Smoothing groups in Maya... slowing down

I am working on a script that emulates the smoothing groups of Max inside Maya. It works fine till now (as much as its done yet) but it progressively slows down as I keep clicking the buttons on the user interface I made.


Each numbered button triggers a function, and earlier I thought there may be some bottlenecks in that function, so I assigned “print” commands as milestones at various points in it. But I found that all the delay happened even before the print at the top of the function statement executed.
So the delay happens before the function even starts being executed, and keeps increasing on each execution.

  1. Can it be because of the large no of variables I declare inside the function. Is there any way to delete the unused variables at the end of the function so they dont take up memory. Though I am clearing the arrays at the end already, with the clear command.

  2. Additionally an old scriptjob is killed and a new one is created everytime the function runs. Can this be leading to the delay?

That’s cool, I’ve always thought smoothing groups were a nice concept, though these days I am quite fond of standard Maya per-edge control.

  1. as long as you are properly scoped, MEL should pop things off the stack just like any other sensible language. If you have variables in global scope, all bets are off. And unless you are seeing a huge memory leak, it shouldn’t have quite the performance repercussions you are describing.

  2. There is a chance that either your group membership ( how are you doing that? ) or your actual calls to set the hardness of edges are creating long, unweildy history chains. Does deleting history temporarily relieve the slowdown? If it is the history, you may be in a tricky situation, because there should be a way to keep it compact, but it’s not clear to me what that is.

Code would help for any deeper debugging than this.

Good Luck!

Thanks Lithium. I’ve found that its actually the history which is causing the slowdown, and it progressively gets slower as the history stack increases.

Correcting that now, and improving my code at the same time…

I’ve gotten the script running fine, added the Clear All button, now just have to add the functionality of Auto Smooth and select by Smoothing Group.

Now there’s another issue-> How to save the smoothing group numbers with the scene file. So that the SG’s of each object get saved alongwith the .ma or .mb files. Right now the smoothing groups are existing as variables in the script editor.
Does anyone have a idea how to save additional info in a .ma or .mb file ?

I have saved the SG’s in .Ma or .Mb files by adding them as separate attributes to each object they are applied.

Now theres another issue. I want to stop the scriptjobs that are going on in the background when the smoothing groups GUI window closes. Does anyone know how to execute a function in MEL when a window closes. I found commands for -minimizeCommand and -restore command which are called when window is minimized or restored, but found no command correspoing to window closure. Does anyone know…

From the docs:

scriptJob -parent string

Attaches this job to a piece of maya UI. When the UI is destroyed, the job will be killed along with it.

Hope that’s what you’re after, else there’s evalDeferred you could try.

-w