Isotropix Forums

Not found item returns error

Clarisse Scripting related topics

Not found item returns error

Unread postby jboissinot » Fri Jun 05, 2020 12:03 am

Hi,

I just wanted to confirm and clarify something regarding the get_item() method that returns the following error:
Code: Select all
LookupError: Failed to find item 'project://scene/light'.
when running:
Code: Select all
ix.get_item('project://scene/light')
and the actual item doesn't exist, while it's said in the documentation that the def clarisse_helper.get_item(item_name) method returns None if it fails to locate the specified item.

Maybe I'm not referring to the proper method here and that's why I wanted to double check actually.

Thanks,
Jeremy
jboissinot
 
Posts: 85
Joined: Tue Jan 29, 2019 10:36 pm

Re: Not found item returns error

Unread postby anemoff » Fri Jun 05, 2020 9:25 am

Hi,

There's a mistake in the documentation. You should use 'item_exists(path)' instead, which actually returns None when the item is not found, whereas 'get_item' will raise an error.

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

Re: Not found item returns error

Unread postby jboissinot » Fri Jun 05, 2020 3:25 pm

Hi Anthony,

In fact, I'm used to use 'item_exists(path)' to check if the item does exist before to use 'get_item(path)' actually but I was just curious to know if we could simply use 'get_item(path)' only which doesn't seem convenient then if it raises an error instead of returning None if the item doesn't exist.

Thank you for confirming though,
Jeremy
jboissinot
 
Posts: 85
Joined: Tue Jan 29, 2019 10:36 pm

Re: Not found item returns error

Unread postby anemoff » Fri Jun 05, 2020 3:29 pm

Actually you don't need to use get_item if item_exists succeeds: item_exists returns the valid item if found.

python code

item = ix.item_exists("path")
if item is None:
# handle missing item, or ignore
print("oops, item not found")
else:
# do something with found item
print("item {} found!".format(item.get_full_name())
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 369
Joined: Wed Jan 13, 2016 10:10 am

Re: Not found item returns error

Unread postby jboissinot » Mon Jun 08, 2020 2:01 pm

Hi Anthony,

Ok good to know, I didn't notice actually. Somehow, I would have expected item_exists() to return True or False and get_item() to return the item or None.

Thanks,
Jeremy
jboissinot
 
Posts: 85
Joined: Tue Jan 29, 2019 10:36 pm

Re: Not found item returns error

Unread postby sam » Mon Jun 08, 2020 3:27 pm

Well item_exists searches for the item. The idea is to return the item if found otherwise, it would do all the work to return a bool and then once again to retrieve the actual item.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1637
Joined: Fri Jan 25, 2013 11:33 pm

Re: Not found item returns error

Unread postby jboissinot » Wed Jun 10, 2020 10:52 pm

Hi Sam,

Yes I see, I think this is just me simply being used to use 'exists' methods that return a bool and didn't actually realize that most 'exists' methods in the Clarisse API return the object if found. So, I'm taking this into account and may revise some code accordingly then.

Thanks,
Jeremy
jboissinot
 
Posts: 85
Joined: Tue Jan 29, 2019 10:36 pm

Re: Not found item returns error

Unread postby sam » Thu Jun 11, 2020 6:18 am

Hi Jeremy,

That's a performance design pattern of Clarisse's API indeed. When an exists method returns directly a bool, you can be sure that the search isn't "costly". In the same way, methods in the API almost never returns an array/vector/list (which must be passed as argument of the method). This is to avoid a potential useless copy of the container.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1637
Joined: Fri Jan 25, 2013 11:33 pm


Return to Scripting