# Pick\_environment based on published file type

**URL:** <https://community.shotgridsoftware.com/t/pick-environment-based-on-published-file-type/3808>\
**Category:** Pipeline Integrations\
**Created:** [November 15, 2019, 2:20am UTC](https://community.shotgridsoftware.com/t/pick-environment-based-on-published-file-type/3808 "2019-11-15T02:20:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhultgre](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/jhultgre/32/487_2.png) [@jhultgre](https://community.shotgridsoftware.com/u/jhultgre)\
**Post date:** [November 15, 2019, 2:20am UTC](https://community.shotgridsoftware.com/t/pick-environment-based-on-published-file-type/3808/1 "2019-11-15T02:20:40Z")

</div>

Is it possible to return a different environment from the pick\_environment hooks based on PublishedFileType when loading something from workfiles or loader?

We have maya files and a custom file format that are both linked to the same task. I need to run a different environment for publishes of our custom filetype to change settings in other apps.

---

<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 15, 2019, 8:53am UTC](https://community.shotgridsoftware.com/t/pick-environment-based-on-published-file-type/3808/2 "2019-11-15T08:53:30Z")

</div>

I think this would be tricky  
It is possible to have a context and thus an environment based on a `PublishedFile`, but usually when you open a `PublishedFile` via workfiles you are actually switching to the context of the entity you selected in the workfiles tree. So the `PublishedFile` is not passed through to the `pick_environment.py` hook.

The other things to consider is, if you open a work file then you have no `PublishedFileType` as there is no `PublishedFile` entity (but perhaps you don’t use work files?). Also the Loader app is used to for importing stuff primarily, so does not modify the current engine context by default.

I could potentially think of a way you might be able to drive the `pick_environment.py` hook though.

In the workfiles2 scene operations hook, you could perhaps store an environment variable holding the file type, when performing an open or save operation. I would perhaps go off the file extension so as to handle both work files and publishes. Then in your `pick_environment.py` you could check for this env var grab the contents. You might also want to clear it at this point as well, I’m not sure.

Similarly if your loader actions are setup to open something, then you could modify the action to set the same env var and initiate an [engine context change.](https://developer.shotgunsoftware.com/tk-core/platform.html#sgtk.platform.change_context)

---

<div class="post-metadata">

**Author:** ![jhultgre](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/jhultgre/32/487_2.png) [@jhultgre](https://community.shotgridsoftware.com/u/jhultgre)\
**Post date:** [November 15, 2019, 7:36pm UTC](https://community.shotgridsoftware.com/t/pick-environment-based-on-published-file-type/3808/3 "2019-11-15T19:36:19Z")

</div>

The place I care about this is in a custom engine and the custom file is supposed to be on the asset instead of the task.

I can probably just have the base hook I’m using for workfiles and loader drop down to an asset context from the task context before opening the file.

I probably also need to strip the task off of the context when publishing the custom file out of maya.

---

<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 18, 2019, 9:32am UTC](https://community.shotgridsoftware.com/t/pick-environment-based-on-published-file-type/3808/4 "2019-11-18T09:32:45Z")

</div>

If your work is going at an asset level, then I would probably setup the workfiles app so that the hierarchy on the tab doesn’t go as far as the Task, so your users are just browsing Assets.
