-
Notifications
You must be signed in to change notification settings - Fork 201
Accessing CustomEntities via the API
kporangehat edited this page Mar 19, 2013
·
2 revisions
Entity types are always referenced by their original names. So if you enable CustomEntity01
and call it "Widget". When you access it via the API, you'll still use CustomEntity01
as the entity_type.
If you want to be able to remember what all of your CustomEntities represent in a way where you don't need to go look it up all the time when you're writing a new script, we'd suggest creating a mapping table or something similar and dumping it in a shared module that your studio uses. Something like the following:
studio_globals.py
entity_type_map = {
'Widget': 'CustomEntity01',
'Foobar': 'CustomEntity02',
'Baz': 'CustomNonProjectEntity01,
}
# or even simpler, you could use a global like this
ENTITY_WIDGET = 'CustomEntity01'
ENTITY_FOOBAR = 'CustomEntity02'
ENTITY_BAZ = 'CustomNonProjectEntity01'
Then when you're writing scripts, you don't need to worry about remembering which Custom Entity "Foobars" are, you just use your global:
my_script.py
import shotgun_api3
import studio_globals
sg = Shotgun('https://mystudio.shotgunstudio.com', 'script_name', '0123456789abcdef0123456789abcdef0123456')
result = sg.find(studio_globals.ENTITY_WIDGET, filters=[['sg_status_list', 'is', 'ip']], fields=['code', 'sg_shot'])