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,

Re: Query Reference Items immediate after creation

Unread postPosted: Fri Jul 23, 2021 5:07 pm
by rahulmishra
Thanks Anthony, that worked great. sorry couldnt reply earlier

Re: Query Reference Items immediate after creation

Unread postPosted: Tue Jul 27, 2021 3:13 pm
by rahulmishra
apologies for late reply. that did help but not entirely. if I run my script more than twice just to load the same reference. it still returns object count 0.

here is what the script is doing...

1. Creating a new scene using

Code: Select all
ix.application.new_workspace()


2. running this script

Code: Select all
import ix
model_ctx = ix.application.get_current_context()
ref = ix.reference_file(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:
    # creating shader connections... here
    print(obj)

Re: Query Reference Items immediate after creation

Unread postPosted: Wed Jul 28, 2021 1:21 pm
by anemoff
Sorry, I couldn't reproduce your issue.
Could you attach the script and tthe USD asset to allow us to investigate?

Thanks.