# Minimal Code to Start Engine

**URL:** <https://community.shotgridsoftware.com/t/minimal-code-to-start-engine/3886>\
**Category:** Pipeline Integrations\
**Created:** [November 21, 2019, 9:37pm UTC](https://community.shotgridsoftware.com/t/minimal-code-to-start-engine/3886 "2019-11-21T21:37:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![craig\_newman](https://avatars.discourse-cdn.com/v4/letter/c/a698b9/32.png) [@craig\_newman](https://community.shotgridsoftware.com/u/craig_newman)\
**Post date:** [November 21, 2019, 9:37pm UTC](https://community.shotgridsoftware.com/t/minimal-code-to-start-engine/3886/1 "2019-11-21T21:37:46Z")

</div>

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

[https://developer.shotgunsoftware.com/tk-core/platform.html#sgtk.platform.start\_engine](https://developer.shotgunsoftware.com/tk-core/platform.html#sgtk.platform.start_engine)

…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)  
engine

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.

---

<div class="post-metadata">

**Author:** ![craig\_newman](https://avatars.discourse-cdn.com/v4/letter/c/a698b9/32.png) [@craig\_newman](https://community.shotgridsoftware.com/u/craig_newman)\
**Post date:** [November 21, 2019, 11:13pm UTC](https://community.shotgridsoftware.com/t/minimal-code-to-start-engine/3886/2 "2019-11-21T23:13:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tannaz](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/tannaz/32/32_2.png) [@tannaz](https://community.shotgridsoftware.com/u/tannaz)\
**Post date:** [November 22, 2019, 12:51am UTC](https://community.shotgridsoftware.com/t/minimal-code-to-start-engine/3886/3 "2019-11-22T00:51:34Z")

</div>

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](https://developer.shotgunsoftware.com/tk-core/initializing.html#bootstrap-api) is a good start.

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

---

<div class="post-metadata">

**Author:** ![craig\_newman](https://avatars.discourse-cdn.com/v4/letter/c/a698b9/32.png) [@craig\_newman](https://community.shotgridsoftware.com/u/craig_newman)\
**Post date:** [November 22, 2019, 7:02pm UTC](https://community.shotgridsoftware.com/t/minimal-code-to-start-engine/3886/4 "2019-11-22T19:02:17Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![philip.scadding](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/philip.scadding/32/30_2.png) [@philip.scadding](https://community.shotgridsoftware.com/u/philip.scadding)\
**Post date:** [November 25, 2019, 12:13pm UTC](https://community.shotgridsoftware.com/t/minimal-code-to-start-engine/3886/5 "2019-11-25T12:13:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![craig\_newman](https://avatars.discourse-cdn.com/v4/letter/c/a698b9/32.png) [@craig\_newman](https://community.shotgridsoftware.com/u/craig_newman)\
**Post date:** [December 2, 2019, 7:44pm UTC](https://community.shotgridsoftware.com/t/minimal-code-to-start-engine/3886/6 "2019-12-02T19:44:26Z")

</div>

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:

**pprint.pprint(engine.commands.keys())**

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…

---

<div class="post-metadata">

**Author:** ![philip.scadding](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/philip.scadding/32/30_2.png) [@philip.scadding](https://community.shotgridsoftware.com/u/philip.scadding)\
**Post date:** [December 3, 2019, 10:46am UTC](https://community.shotgridsoftware.com/t/minimal-code-to-start-engine/3886/8 "2019-12-03T10:46:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![craig\_newman](https://avatars.discourse-cdn.com/v4/letter/c/a698b9/32.png) [@craig\_newman](https://community.shotgridsoftware.com/u/craig_newman)\
**Post date:** [December 3, 2019, 4:22pm UTC](https://community.shotgridsoftware.com/t/minimal-code-to-start-engine/3886/9 "2019-12-03T16:22:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![philip.scadding](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/philip.scadding/32/30_2.png) [@philip.scadding](https://community.shotgridsoftware.com/u/philip.scadding)\
**Post date:** [January 17, 2020, 5:39pm UTC](https://community.shotgridsoftware.com/t/minimal-code-to-start-engine/3886/11 "2020-01-17T17:39:59Z")

</div>

Just to quickly follow up, the guide is now live for everyone [here](https://developer.shotgunsoftware.com/3d8cc69a/?title=Bootstrapping+and+running+an+app)!
