I think if you want to export the thumbnail and import it as a texture assets in python or bp, you need do a little c++ work: export a Blueprint callable function which export the thumbnail as a image, then import it as texture2D assets with python script or bp.
The source of the export function from JoeRadak:
Exporting Thumbnails to PNGs - Pipeline & Plugins / Editor Scripting - Unreal Engine Forums
/** .h
* Save the Thumbnail of assets to disc.
*
* @param ObjectPath The specified path of asset
* @param OutputPath Thumbnail output path
*/
UFUNCTION(BlueprintCallable, meta = (Keywords = "Python Editor"), Category = "PythonEditor")
static void SaveThumbnail(FString ObjectPath, FString OutputPath);
and the implementation in .cpp
/** .cpp */
void UPythonBPLib::SaveThumbnail(FString ObjectPath, FString OutputPath)
{
FAssetRegistryModule& AssetRegistryModule = FModuleManager::Get().LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));
FAssetData AssetData = AssetRegistryModule.Get().GetAssetByObjectPath(*ObjectPath);
UObject* MyObject = AssetData.GetAsset();
if (MyObject)
{
FObjectThumbnail* ObjectThumbnail = ThumbnailTools::GenerateThumbnailForObjectToSaveToDisk(MyObject);
if (ObjectThumbnail)
{
IImageWrapperModule& ImageWrapperModule = FModuleManager::Get().LoadModuleChecked<IImageWrapperModule>(TEXT("ImageWrapper"));
TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
ImageWrapper->SetRaw(ObjectThumbnail->GetUncompressedImageData().GetData(), ObjectThumbnail->GetUncompressedImageData().Num(), ObjectThumbnail->GetImageWidth(), ObjectThumbnail->GetImageHeight(), ERGBFormat::BGRA, 8);
if (ImageWrapper)
{
const TArray64<uint8>& CompressedByteArray = ImageWrapper->GetCompressed();
FFileHelper::SaveArrayToFile(CompressedByteArray, *OutputPath);
}
}
}
}
Then, we can export the thumbnail with python like this:
def on_button_ExportThumbnail_click(self):
print('on_button_ExportThumbnail_click')
folder = "/Game/YourAssetsFolder"
asset_paths = unreal.EditorAssetLibrary.list_assets(folder, recursive=True)
target_folder = r"D:\YouArtSourceFolder"
for i, asset_path in enumerate(asset_paths):
asset = unreal.load_asset(asset_path)
if type(asset) is not unreal.StaticMesh: # change the types
continue
name_with_folder = asset_path[len(folder)+1:].split(".")[0]
target_file_path = os.path.join(target_folder, f"{name_with_folder.replace('/', '_')}.png")
unreal.PythonBPLib.save_thumbnail(asset_path, target_file_path)
After that, import the exported thumbnail as texture
import_task = unreal.AssetImportTask()
# set the import_task.filename, destination_path, options and so on
import_task.filename = texture_path
# ...
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([import_task])
Hope, that helps.