[Closed] GetClassInstances targets to speed things up
I’m a newbie but currently experimenting with various ways to, and the relative speeds of, collecting all scene materials and I’ve noticed the following on a test scene:
for j in material.classes do for k in (getclassinstances j) do append aAllMaterials k
takes an eternal 6.525 seconds to execute while the following:
for i = 1 to xrefs.getXRefFileCount() do
(
root1 = (xrefs.getXRefFile i).tree
for j in material.classes do for k in (getclassinstances j target:root1) do append aXrefMaterials k
)
takes only 0.092 seconds to execute and populate a dotnet list view when run against a file that xrefs in the same test scene the original code was run against. I’m new to maxscript and don’t really understand the exact implications of how the .tree is speeding up the process of collecting materials from the xref file and when used with the taget, is making it orders of magnitude faster. Two questions:
-
Is there a good way to use this same concept to speed up the original code when executed within a local, non xrefed scene?
-
Is there a technique that is considered the de facto fastest way to gather all scene materials into an array without having to manually iterate down through each material type – multisubobject, vray 2-sided, blends, etc that are containers for other materials?
Thought I’d post an update that the sLib script in Neil Blevins’ Soulburn library is able to build the array in a local (non xref file) in 0.048 seconds.