[Closed] nested Xrefs
So I need to loop recursively through my xrefs (which could have xrefs in them as well, hence the need for recursive)
I have an array with primitive types
primitiveList = #("box","cone","sphere","geosphere",
"cylinder","Tube","torus","pyramid",
"teapot","plane","line","rectangle",
"circle","ellipse","arc","donut",
"ngon","star","text","helix","egg","section")
what I need is to list the xrefScene + the objects in that scene that are named according to the objects in the primitiveList.
BUT, it could happen an xref is xref’d twice, obviously I only want to list it once
(the script will be used to determin if there are primitives in the xref so I would only need to list it for each unique xref)
I found this rough gem
fn collectXRefScenes root: nested:on scenes:#() objects:#()= (
for i=1 to xrefs.getXRefFileCount root:root do
(
local xScene = xrefs.getXRefFile i root:root
appendifunique scenes xScene as string
if nested do collectXrefScenes root:xScene scenes:scenes
)
scenes
)
collectXrefScenes()
above unfortunately only adds lvl 1-1 and lvl 2-1 and not the twice xrefd lvl 1-2 when running it on attached “rp check.max” :surprised
so how do I get a list of uninque xrefs which have primitive objects in them
something like this is what I’m looking for:
xref: lvl 1-1:
Rectangle001
Sphere001
xref: lvl 1-2:
Pyramid001
xref: lvl 2-1:
Donut001
struct XRefSceneStruct (scene, nodes = #())
primitives = #(box, sphere, cone, cylinder)
fn isObjectKindOf node classes baseobject:on =
(
object = if baseobject then node.baseobject else node
finditem classes (classof object) > 0
)
fn collectXRefScenesData root: nested:on scenes:#() classes: baseobject:off =
(
for k=1 to xrefs.getXRefFileCount root:root do
(
xsc = xrefs.getXRefFile k root:root
nodes = #()
for root in xsc.tree.children do join nodes root
if classes != unsupplied do
(
nodes = for node in nodes where (isObjectKindOf node classes baseobject:baseobject) collect node
)
scene = XRefSceneStruct scene:xsc nodes:nodes
append scenes scene
if nested do collectXRefScenesData root:xsc scenes:scenes classes:classes baseobject:baseobject
)
scenes
)
scenes = collectXRefScenesData classes:primitives --baseobject:on
i’ve modified my original function. now it collects scenes as a structure – scene + nodes
optionally you can pass a list of classes you are interested to search, and how to search (by it’s baseobject or current object)
thanks for that,
but I not so much need the objects class, but the objects name (If an object has a primitive name, then there’s a high chance our pipeline will not render a mask for it)
apart from that, why won’t appendifunique work on adding the xrefs to an array ?