[Closed] Collect SceneMaterials from Xrefs
I have script that is currently doing this…
for i = 1 to xrefs.getXRefFileCount() do
(
xFile = xrefs.getXRefFile i
root1 = (xrefs.getXRefFile i).tree
Join arrayXrefMaterials (getClassInstances VrayMtl target:root1)
)
but I now need to collect instances of all materials, not just the Vray Materials. Basically the equivalent of the SceneMaterials array for each xref. I can’t really come up with a good way of doing this other than manually going through each material class one by one OR iterating through each object but that gets messy because you have to dig down into all of the multisubobject materials, two-sided materials, etc. I feel like I am overlooking something obvious. Is there a clean and easy way to do this?
Thanks.
the good old “search” led me to this, which works…
for i = 1 to xrefs.getXRefFileCount() do
(
xFile = xrefs.getXRefFile i
root1 = (xrefs.getXRefFile i).tree
for j in material.classes do for k in (getclassinstances j target:root1) do append aXrefMaterials k
)
using getclassinstances is much slower than take a maretial from every xref node.
fn collectAllXrefMaterials root: materials:#() =
(
for k=1 to xrefs.getXRefFileCount root:root do
(
xsc = xrefs.getXRefFile k root:root
for child in xsc.tree.children do
(
nodes = join #() child
for node in nodes where node.material != undefined do
(
if (appendIfUnique materials node.material) do join materials (join #() node.material)
)
)
collectAllXrefMaterials root:xsc materials:materials
)
ok
)
(
t1 = timestamp()
xmats = #()
collectAllXrefMaterials materials:xmats
xmats = makeUniqueArray xmats
format "count:% time:%
" xmats.count (timestamp() - t1)
)
try to compare to ‘getclassinstances’ method
PS. there is some incorrect thing in my code. i left it in purpose, just letting you understand how it works, find and fix the issue.
Hey Denis,
Thank you for the responses. I’ve been saying that a lot lately :keenly: I’m away from my computer on vacation until after New Years but I wanted to write and say thank you for the input and I’ll wrap my head around what you are doing when I am back in the office. I sort of see what you are doing but I am slow and new at this so I’ll need to really step through each step to fully “get it”. Anyway, Happy Holidays and thanks again!