improving script performance

Hi,
this is more a general question, but if needed I can post the scripts that I'm talking about next:

I do have a script, that will look at each object in the scene that has a material, copy that material,give it the same name as the object and put that material into a library, which is saved as a file to disk. So for 470 textured objects in the scene I will get a material library containing 470 materials all named as the original objects.

The next script will load that material library and look at the scene: If the material name is the same as the name of an object in the scene, this material will be applied to that object. Ive written both scripts so that I can finalize my shaders and textures in one scene and then easily put those materials into already existing and animated scenes (with the same objects), that yet dont have any materials.

I currently have about 700 objects in the scene, so this script will have to check for corresponding names 470 x 700 = 329.000 times. This is kinda slow, but not thaaat slow. Ive build a progress bar to get a visual feedback of the progress, and it takes less than a minute on my computer to update the materials.

My problem is, after the progress is finished, Max freezes for about 5-10 minutes, not allowing me to do anything. Ive tried the "with redraw off" context, because I thought that could be an issue, but it didn't help. I guess I could improve the checking-progress (e.g. if object gets a material from library, exclude it from remaining search processes). But what does Max slow down so very much after all those materials were put back into the scene? I have the same issue on another script, that detaches all polygons of a model to separate objects. It also has a progress bar, and will freeze for 2-3 minutes after its done. Any ideas why?

Regards

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
br0t's picture

check your skype :P

check your skype :P

Never get low & slow & out of ideas

Graph's picture

the hell, shouldnt

the hell, shouldnt freeze
check your inbox

Raphael 'Insanto' Steves
http://Graph.Net84.Net

Graph's picture

local bgWorkerThread =

local bgWorkerThread = dotnetobject "CSharpUtilities.SynchronizingBackgroundWorker"
 
bgWorkerThread.WorkerSupportsCancellation = cancelEnable
bgWorkerThread.WorkerReportsProgress = true		
 
fn doTheWorkBaby =
(
   --do stuff here
)
 
dotNet.addEventHandler bgWorkerThread "DoWork" doTheWorkBaby
bgWorkerThread.RunWorkerAsync()

this code basically runs some code async || does it in the background
your code belongs.. not to me, but inside the function and can be given back to the main part but for that you need to check the bgworker in intervals for the result (if the function is done running) wich makes the whole thing slow again..so i'd advise against that. simply put you gotta make sure everything is done inside the function and you dont need any result returned, have phun

edit: just freeze all nodes at the beginning and subsequently unfreeze them as your done with the changes to each one.. that way you wont create a singularity :P

Raphael 'Insanto' Steves
http://Graph.Net84.Net

br0t's picture

Thanks for your efforts! Ive

Thanks for your efforts! Ive put everything except the "getSavePath" command and your dotnet code into the function, and it will work correctly as before, but unfortunately max still freezes afterwards for like 2 minutes (in a testscene with just about 10 objects and materials!).
Why does it freeze at all?? Really pisses me off at the moment...

Oh and sadly I ignored your tip to freeze all objects, and now have to deal with a supermassive black hole sucking up my viewports

Never get low & slow & out of ideas

br0t's picture

what is a prep script for

what is a prep script for CE²? if you like you can have a look at the attached files (as I said its all pretty rough :/). That .net thing sounds interesting, I have no experience with .net yet, maybe you could explain that a little further?

Cheers

AttachmentSize
scenematstomatlibbyobjectname.ms 1.12 KB
updatematsfrommatlibbyobjectname.ms 1.06 KB

Never get low & slow & out of ideas

Graph's picture

that sounds an awefull lot

that sounds an awefull lot like prep scripts for CE² or ³, mind posting the code?

hmm you could always put it in a function and run it async with .net so your max wont freeze up..

Raphael 'Insanto' Steves
http://Graph.Net84.Net

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.