Going from Shotgun Python console to maya console

Hello good day I coded all may code in the Shotgun python console and would like to move it over two maya now i got Shotgun Desktop installed and going

I did realize if i start maya with shotgun i can do (import sgtk)

But i would like to do the command imports without doing this so even if someone opens maya without shotgun that this script can still work please it would be appreciated

So basically i want all the commands that work in the Shotgun python console to work in maya aswel please

1 Like

Hi @WakaKrazyBunBun, I’ve moved this post to the “Pipeline Integrations” category so that it will get seen by some of our Pipeline/Toolkit folks. Just letting you know!

That is completely fine thank u for moving it two the correct area actually thank u

Hello – you’ll want to add the path to Toolkit Core API to your sys.path in Python; then you should be able to import sgtk. If you have a centralized Toolkit pipeline configuration, by default it should have its own copy of the Core API in the install/core/ directory, and within that, we want to get to the python/ directory. So, in my case, my pipeline config is in /sgtk/software/shotgun/goats, so the following works:

import sys
sys.path.append('/sgtk/software/shotgun/goats/install/core/python')

This will allow your code to run, but depending on what you’re doing in your script with the Toolkit API, it may require Toolkit’s tk-maya engine to be running and/or for you to have a Toolkit context.

To have this path added to your sys.path every time Maya is launched, you can add it to the PYTHONPATH environment variable via the Maya.env file, or add the above lines of Python to Maya’s user_setup.py file. You can see the sections on Initializing the Maya Environment in and for Python and Adding Items to your Python Path in the Python in Maya page from Maya’s documentation.

Let us know if you hit any snags with that!

2 Likes

So i dont completely understand how to do this so i installed Shotgun desktop and i esentially just want two grab from where it grabs it code for shotgun

So where and how would i path that and import that

I am using the sg\shotgun command and the sgtk

Hi @WakaKrazyBunBun, I’ve messaged you privately with a link to some documentation that is in the works, it may help answer some of your questions.
Let us know if not.

2 Likes

Thank u I am currently looking at it i just wanne say thank u for your help i am still new two coding and things

1 Like

so I am running into a difrent problem now where it says the context dosent excist there so how could i go about fixing that

engine = sgtk.platform.current_engine()
project = engine.context.project
sg = engine.shotgun

i have imported and set the sys.path now and everything and then i am folowing another vedio that says to get sg in u do it like that but i am getting a context error

o btw that line of code works if i open the project with your software but if i open maya on the side it dosent seem to be working

The engine = sgtk.platform.current_engine() will only return an engine, if an engine is running.

If you launched Maya without the Shotgun integration, and then imported sgtk, and then tried to run that, there wouldn’t be an engine present.

If you are using a centralized config, then you can use the sgtk API without bootstrapping the whole configuration. You would usually use one of the factory methods to create your self an Sgtk instance, and access the Shotgun connection through there. Something like:

import sgtk

tk = sgkt.sgtk_from_entity("Project", 1234)
sg = tk.shotgun

If you are using a distributed config then you will need to follow the bootstrap guide I privately linked you, and perform a bootstrap of the engine.

The code after the

is this the project id or can it be 1234 sorry very dumb question but just wanne make sure because if this is the project id i will need to start up the Api to set it up ass i understand to get the project id 1st

If you look at the factory methods documentation it details the arguments required for the method, but yes, in this case, the 1234 was representing the project ID.

Okay cool if i get stuck il come back thank u for your assistance and your patience with me

2 Likes