[Closed] Collecting used classes
Hi, I’m trying to gather certain classes (geometry, modifiers, materials, maps…) that are used in the scene.
I'm using .classes property to get all the classes and filtering those out.
So far, I ended up with two methods:
METHOD A:
fn getUsedModClassesA =
(
local preUsedClasses = for i in modifier.classes where i.dllIsLoaded != undefined collect i
local preUsedInstances = for i in preUsedClasses collect getClassInstances i
local theUsedClasses = for i in 1 to preUsedInstances.count where preUsedInstances[i].count != 0 collect preUsedClasses[i]
)
METHOD B:
fn getUsedModClassesB =
(
local usedDLLs = fileProperties.getItems "Used Plug-ins"
local preUsedClasses = for i in modifier.classes where (findItem usedDLLs i.dllName != 0) collect i
local preUsedInstances = for i in preUsedClasses collect getClassInstances i
local theUsedClasses = for i in 1 to preUsedInstances.count where preUsedInstances[i].count != 0 collect preUsedClasses[i]
)
Both of the methods works well..
Method A is much slower.. because it needs to check all the mod classes if it is loaded.
Method B is much faster.. but it needs to be a saved/updated scene since it reads the max file properties.
I want to use B since it is faster, but I cannot ask the user to always save their scene just to be sure that the collected classes are updated.
If I use A, I'm worried that it may not perform very well on heavier scenes.
My question now is.. any of you guys know of another method to collect used classes?
Thanks,
Jeff Lim
I can think of how to do it using the SDK: Enumerate all the animatables and for each one save their class in a std::set
method B is not correct. because it might be a plugin that defines multiple classes. i do it all the time.
method A is correct but using getClassInstances for every class is slow because it iterates all the same maxobjects again and again.
so it will be much faster to collect modifier classes for example as:
used = #()
for obj in objects do for modi in obj.modifiers do appendifunique used (classof modi)
in the same loop you can collect geometry classes as well…
but i agree with lo that the universal solution is the iterating all animatables using sdk.
it’s pretty simple. the code is almost the same as getClassInstances which you can find in max sdk examples
Thanks Dennis!
Yeah, I was able to narrow down the cause of the slowness from the getClassInstances… And I was also trying to avoid looping through all the scene objects. I’ll give that one a go as it seems that it is the most straight forward method for now.
Cheers!
Jeff Lim