Isotropix Forums

Query Reference Items immediate after creation

Clarisse Scripting related topics

Query Reference Items immediate after creation

Unread postby rahulmishra » Thu Jun 10, 2021 5:05 pm

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
rahulmishra
 
Posts: 3
Joined: Thu Jun 10, 2021 4:39 pm

Re: Query Reference Items immediate after creation

Unread postby anemoff » Fri Jun 11, 2021 10:39 am

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,
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 413
Joined: Wed Jan 13, 2016 10:10 am

Re: Query Reference Items immediate after creation

Unread postby rahulmishra » Fri Jul 23, 2021 5:07 pm

Thanks Anthony, that worked great. sorry couldnt reply earlier
rahulmishra
 
Posts: 3
Joined: Thu Jun 10, 2021 4:39 pm

Re: Query Reference Items immediate after creation

Unread postby rahulmishra » Tue Jul 27, 2021 3:13 pm

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)
rahulmishra
 
Posts: 3
Joined: Thu Jun 10, 2021 4:39 pm

Re: Query Reference Items immediate after creation

Unread postby anemoff » Wed Jul 28, 2021 1:21 pm

Sorry, I couldn't reproduce your issue.
Could you attach the script and tthe USD asset to allow us to investigate?

Thanks.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 413
Joined: Wed Jan 13, 2016 10:10 am


Return to Scripting
cron