Page 1 of 1

Query Reference Items immediate after creation

Unread postPosted: Thu Jun 10, 2021 5:05 pm
by rahulmishra
Hi,

I'm trying to list all the objects of a USD reference immediately after reference creation. the code works if I run first and second part separately, but fails when I run all at once. Could you please let me know what am I missing..

First Part

Code: Select all
import ix
model_ctx = ix.application.get_current_context()
ref = ix.cmds.CreateFileReference(str(model_ctx), [r"X:\Testing\cubes.usd"])


Second Part

Code: Select all
geom_objects = ix.api.OfObjectArray()
model_ctx.get_all_objects(geom_objects)
for obj in geom_objects:
    print(obj)



Thank you

Re: Query Reference Items immediate after creation

Unread postPosted: Fri Jun 11, 2021 10:39 am
by anemoff
Hi,

To let the loading finish before calling the 2nd part, you need to let the application process pending events to finish executing the USD reference loading.
I've also edited the script to list only objects in the reference context.

Code: Select all
import ix
model_ctx = ix.application.get_current_context()
ref = ix.cmds.CreateFileReference(str(model_ctx), [r"X:\Testing\cubes.usd"])

# Process application events to finish loading the USD reference
ix.application.check_for_events()

geom_objects = ix.api.OfObjectArray()
ref.get_all_objects(geom_objects)
for obj in geom_objects:
    print(obj)


Cheers,