Getting current context or entity


I am writing tools in Maya and trying to retrieve information from the Shotgun API. But I don't see a way to get the current context or entity in Maya. The Work Area Info works fine and showing me the current project and shot so I wonder how that works. I have looked through the API and there are functions like context_from_path(),context_from_entity(), context.entity. But how do I get the path in the first place?

It would be easy to store the work area path as environment variable when maya is launching or use the current file path as the path. But there are exceptions which may make these methods unreliable. So I am wondering what is the recommended method to achieve this.

This question seems very fundamental but I am unable to find any information on this forum. I apologize if this has been asked before and please point me to the forum page. Thank you.

2 条评论

  • 0
    Alan Dann

    Hi Chai,

    You can access the current context via the current engine by doing the following in Python:

    import sgtk

    current_engine = sgtk.platform.current_engine()

    context = current_engine.context

    The current_engine instance also gives you access to things like the currently registered apps & commands if you need them - check out the documentation here.

    Does that help?



  • 0
    CHAI Qian-Hao

    Cool. So I have been looking at the wrong place. Thanks.