# Python to Open / Save assets using Editor

**URL:** <https://forums.unrealengine.com/t/python-to-open-save-assets-using-editor/119251>\
**Category:** Editor Scripting\
**Tags:** unreal-engine\
**Created:** [November 26, 2018, 2:29pm UTC](https://forums.unrealengine.com/t/python-to-open-save-assets-using-editor/119251 "2018-11-26T14:29:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ExtraLifeMatt](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/extralifematt/32/918695_2.png) [@ExtraLifeMatt](https://forums.unrealengine.com/u/ExtraLifeMatt)\
**Post date:** [November 26, 2018, 2:29pm UTC](https://forums.unrealengine.com/t/python-to-open-save-assets-using-editor/119251/1 "2018-11-26T14:29:55Z")

</div>

Hey all,

I noticed the unreal.AssetTools has an open\_editor\_for\_assets, but I’m unsure of how to force a save through the editor for those open assets (I generally run some object clean-up logic in my editors during asset save). Has anyone come across this?

---

<div class="post-metadata">

**Author:** ![AlexQuevillon](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexquevillon/32/751975_2.png) [@AlexQuevillon](https://forums.unrealengine.com/u/AlexQuevillon)\
**Post date:** [December 16, 2018, 6:58pm UTC](https://forums.unrealengine.com/t/python-to-open-save-assets-using-editor/119251/2 "2018-12-16T18:58:38Z")

</div>

Good morning!

I have some videos that might help with this.  
Sadly, I had to use a little bit of C++ to close the assets and get the opened assets list, but the saving part is all in Python 🙂

[How to Open and Close Assets](https://youtu.be/1eNluZ3r-mM)

```auto

# unreal.AssetToolsHelpers
# https://api.unrealengine.com/INT/PythonAPI/class/AssetToolsHelpers.html
# unreal.AssetTools
# https://api.unrealengine.com/INT/PythonAPI/class/AssetTools.html
def openAssets():
    assets = [unreal.load_asset('/Game/Textures/TX_LightSpotMove'),
              unreal.load_asset('/Game/SkeletalMeshes/TutorialTPP_Mat'),
              unreal.load_asset('/Game/Sounds/S_CompileSuccess')]
    unreal.AssetToolsHelpers.get_asset_tools().open_editor_for_assets(assets)

```

```auto

// PublicDependencyModuleNames -> "UnrealEd"
#include "Editor/UnrealEd/Public/Toolkits/AssetEditorManager.h"
void UCppLib::CloseEditorForAssets(TArray<UObject*> Assets) {
    FAssetEditorManager& AssetEditorManager = FAssetEditorManager::Get();
    for (UObject* Asset : Assets) {
        AssetEditorManager.CloseAllEditorsForAsset(Asset);
    }
}

```

[How To Save Assets](https://youtu.be/kpaS98YRT00)

```auto

# unreal.EditorAssetLibrary
# https://api.unrealengine.com/INT/PythonAPI/class/EditorAssetLibrary.html
def saveAsset():
    unreal.EditorAssetLibrary.save_asset('/Game/Textures/TX_LightSpotMove', only_if_is_dirty=False)

```

Let me know if it is what you are looking for 🙂  
Also, if you don’t mind, you got me interrested. What kind of clean-up you are doing?

---

<div class="post-metadata">

**Author:** ![ExtraLifeMatt](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/extralifematt/32/918695_2.png) [@ExtraLifeMatt](https://forums.unrealengine.com/u/ExtraLifeMatt)\
**Post date:** [December 17, 2018, 5:26pm UTC](https://forums.unrealengine.com/t/python-to-open-save-assets-using-editor/119251/3 "2018-12-17T17:26:48Z")

</div>

> [@AlexQuevillon](#):
>
> Good morning!
> 
> I have some videos that might help with this.  
> Sadly, I had to use a little bit of C++ to close the assets and get the opened assets list, but the saving part is all in Python 🙂
> 
> [How to Open and Close Assets](https://youtu.be/1eNluZ3r-mM)
> 
> ```auto
> 
> # unreal.AssetToolsHelpers
> # https://api.unrealengine.com/INT/PythonAPI/class/AssetToolsHelpers.html
> # unreal.AssetTools
> # https://api.unrealengine.com/INT/PythonAPI/class/AssetTools.html
> def openAssets():
> assets = [unreal.load_asset('/Game/Textures/TX_LightSpotMove'),
> unreal.load_asset('/Game/SkeletalMeshes/TutorialTPP_Mat'),
> unreal.load_asset('/Game/Sounds/S_CompileSuccess')]
> unreal.AssetToolsHelpers.get_asset_tools().open_editor_for_assets(assets)
> 
> ```
> 
> ```auto
> 
> // PublicDependencyModuleNames -> "UnrealEd"
> #include "Editor/UnrealEd/Public/Toolkits/AssetEditorManager.h"
> void UCppLib::CloseEditorForAssets(TArray<UObject*> Assets) {
> FAssetEditorManager& AssetEditorManager = FAssetEditorManager::Get();
> for (UObject* Asset : Assets) {
> AssetEditorManager.CloseAllEditorsForAsset(Asset);
> }
> }
> 
> ```
> 
> [How To Save Assets](https://youtu.be/kpaS98YRT00)
> 
> ```auto
> 
> # unreal.EditorAssetLibrary
> # https://api.unrealengine.com/INT/PythonAPI/class/EditorAssetLibrary.html
> def saveAsset():
> unreal.EditorAssetLibrary.save_asset('/Game/Textures/TX_LightSpotMove', only_if_is_dirty=False)
> 
> ```
> 
> Let me know if it is what you are looking for 🙂  
> Also, if you don’t mind, you got me interrested. What kind of clean-up you are doing?

Thanks Alex, I’ll give that a try.

I have some editor only fields that I then read and optimize to a more performant runtime bitfield / whatever implementation on Save. Just simple stuff like that.
