Minimal Code to Start Engine

I want to start an engine using the minimal code for testing. Base on this document:

…this code can be used:

import sgtk
tk = sgtk.sgtk_from_path("/studio/project_root")
ctx = tk.context_empty()
engine = sgtk.platform.start_engine(‘tk-maya’, tk, ctx)

Consequently, when I run this line:

tk = sgtk.sgtk_from_path(r"C:\MasterProjects\test_dev_01")

I get the following error:

TankInitError: You are loading the Toolkit platform from the pipeline configuration located in ‘C:\Users\Craig\AppData\Roaming\Shotgun\machine\site.basic.desktop\cfg’, with Shotgun id None. You are trying to initialize Toolkit from C:\MasterProjects\test_dev_01, however that is not associated with the pipeline configuration. Instead, it’s associated with the following configurations: ‘None’ (Pipeline config id 1, Project id 243), ‘None’ (Pipeline config id 3, Project id 243), ‘None’ (Pipeline config id 4, Project id None), ‘None’ (Pipeline config id 5, Project id None), ‘None’ (Pipeline config id 39, Project id None), ‘None’ (Pipeline config id 40, Project id None), ‘None’ (Pipeline config id 41, Project id None), ‘None’ (Pipeline config id 42, Project id None), ‘None’ (Pipeline config id 78, Project id None).

It appears I need additional code to associate a specific configuration. Any insights on the minimal code to start an engine are appreciated.

1 Like

With a bit of experimentation I found this worked:

tk = sgtk.sgtk_from_path(r"C:\Users\Craig\AppData\Roaming\Shotgun\machine\p243c3.basic.shotgun\cfg")

But the next line fails:

engine = sgtk.platform.start_engine(‘tk-aftereffects’, tk, ctx)

TankMissingEngineError: Cannot find an engine instance tk-aftereffects in Environment site.yml.

Thanks again

1 Like

Hi Craig –

As the error states, you’ll need to have the engine that you want to initialize defined in the context in which you want it to run. So, I guess the question here is what are you passing as the value of ctx?

As a side note, I’m not sure of your use case, but you might want to consider the Bootstrap API, as it’s designed for exactly what you’re mentioning. The code snippet here is a good start.

Let us know if you have any questions as you go along.

1 Like

Thanks Tannaz -

Yes, the bootstrap code is probably better in this case. However, I have a couple of questions. I want to run the After Effects engine.

In this line of code I don’t know what should be here in order to run After Effects:

mgr.plugin_id = "basic.my_toolkit_plugin"

I assume I should put “tk-aftereffects” in this line:

e = mgr.bootstrap_engine(“tk-aftereffects”, entity={“type”: “Shot”, “id”: 2411})

By the way, I did try these two lines:

mgr.plugin_id = "basic.aftereffects"
e = mgr.bootstrap_engine(“tk-aftereffects”, entity={“type”: “Shot”, “id”: 2411})

but the bootstrap hangs forever without crashing or giving any error.

Thanks again !

1 Like

Hey Craig

I’m writing a guide at the moment on bootstrapping which is now going into review. It’s not quite ready for a full public release but I’ve sent you a private message with a link to a preview build.

The plugin id itself, doesn’t matter a great deal, it’s kind of an arbitrary value, and it will create a cached config on disk in a folder named after the plugin id. It also does a few other things, but for your purpose I would probably just go with a value of basic.adobe since that is what the standard aftereffects launch process would register it as.

1 Like

Hi Philip,

The bootstrap guide is great, thanks. The only addition to the guide might be an addendum listing the fact that basic.adobe is used for the After Effects (and Photoshop?) plugin, as I haven’t seen that documented anywhere. Or simply list every application and the corresponding plugin name.

I was able to bootstrap After Effects using the guide. After the bootstrap, it would not print out any info. For example, this wouldn’t print:


And the engine seemed to “hang”. However, for now this answers my question and I don’t have to use the bootstrap, so I consider this resolved. Thanks, again…


Hi Craig

Sorry, I think there may have been a bit of misunderstanding on my part here, I don’t think I fully appreciated what you were asking which was my fault.

You can bootstrap the tk-shell engine and then launch Aftereffects via engine.execute_command("after_effects_cc_2019",[]), which will start aftereffects up.

But I think bootstrapping the After Effects engine specifically would be tricky.
Each engine will only bootstrap in the software it was designed for. The After Effects engine doesn’t know how to operate without After Effects being present.
The After Effects and Photoshop engines are probably not easy to bootstrap manually even in After Effects because those applications don’t support Python natively, so when we launch them in Toolkit, we ensure that the Toolkit plugin is installed and that a separate Python instance is initiated which then communicates to the plugin.

With something like Maya for example, you can launch Maya without the Shotgun integrations, and then run the bootstrap code from within Maya and the integrations/Shotgun menu will start.

I’m sorry I misled you there.


Thanks, Philip. Yes, this all makes sense regarding After Effects and Photoshop, as they use an ECMA/Javascript “variation” for the API and Toolkit uses RPC to communicate with the API.

Likewise, I understand now that bootstrap code for an application like Maya would need to be started from within the application. Overall, my original view regarding minimal code to start an engine was uninformed. I think I see the picture clearer now.

Again, the bootstrap guide is great with tk-shell. Thanks again, Philip, for your time in clearing all this up.


Just to quickly follow up, the guide is now live for everyone here!

1 Like