Skip to main content
badde.media
Known Participant
September 20, 2023

Sampler hangs when running example export_all.py

  • September 20, 2023
  • 2 replies
  • 262 views

As mentioned above. I'm trying to run the unmodified version of the export_all.py script found here:
https://helpx.adobe.com/substance-3d-sampler/scripting-and-development/create-a-script-with-python/example-scripts.html
When I start the script, nothing happens. Nothing at all, no UI interactivity, no files are being exported, nothing. I'd call it a crash, but it still shows changing CPU activity - what doesn't have to mean much.

The script seems to be fine, so I assume there are some heavy bugs in Sampler which make it impossible to be used in a production environment. Which is pretty disappointing.

 

App version: Latest supplied by the Adobe CC app, freshly reinstalled
Platform: Windows
Steps to reproduce: Open file, start script, crash

Expected result: Files get exported
Real result: App hangs infinitely, no files get exported


This is a critical error in Substance Sampler's Python pipeline.Not even the most simple example works. Or the documentation is outdated.

 

2 replies

badde.media
Known Participant
October 2, 2023

This one should work:

 

import substance_sampler as ssa
import os
import sys


# Function to export as SBSAR with default options
def export_as_sbsar(asset_to_export, w_res, h_res, destination_path):
    asset_to_export.export(w_resolution=w_res,
                           h_resolution=h_res,
                           path=destination_path)


# Function to export as PNG with Unreal Engine 4 export preset
def export_as_png_with_ue4_preset(asset_to_export, w_res, h_res, destination_path):
    [ue4_export_preset] = ssa.get_export_presets("Unreal Engine 4")
    asset_to_export.export(w_resolution=w_res,
                           h_resolution=h_res,
                           path=destination_path,
                           format=ssa.png,
                           preset=ue4_export_preset)

# Verify if the project is already saved to get its path
if ssa.save_project():
    ssa.save_project()

    # Get the folder path of the project
    export_path = os.path.dirname(ssa.get_project_path())

    # Get all assets of your project in a list
    all_project_assets = ssa.get_project_assets()

    # Go Through the list of all assets
    for asset in all_project_assets:
        # Export each asset with the resolution 2048x2048px next to the project file (.ssa)
        try:
            print(f"Exporting asset {asset} to {export_path} with resolution 1024x1024px as SBSAR...")
            export_as_sbsar(asset, 1024, 1024, export_path)
        except:
            print(f"failed: Exporting asset {asset} to {export_path} with resolution 1024x1024px as SBSAR ")

        # Export each asset with the resolution 2048x2048px in a folder "textures" next to the project file (.ssa)
        try:
            print(f"Exporting asset {asset} to {export_path} with resolution 1024x1024px as PNG with UE4 preset...")
            export_as_png_with_ue4_preset(asset, 1024, 1024, os.path.join(export_path, "textures"))
        except:
            print(f"failed: Exporting asset {asset} to {export_path} with resolution 1024x1024px as PNG with UE4 preset")

else:
    print("Save first your project", file=sys.stderr)

 

badde.media
Known Participant
September 29, 2023

I've found out that the function asset.export, that has been used in the example script, is deprecated. Using asset.export_material, as the error message told me to do, I now get the error "name 'true' is not defined" - although the asset name should be the name by default, and also when I explitely defined "name=asset_to_export.name" in the function when calling asset.export_to_material. I assume that this is a bug.

 

Oh yes, worth mentioning that the line "if ssa.save_project()" caused Sampler to hang. With it commented out, the script runs without crashing Sampler.

 

Here's my modified export_all.py script:

 

import substance_sampler as ssa
import os
# import sys

print("Exporting all assets...")
# Function to export as SBSAR with default options
def export_as_sbsar(asset_to_export, w_res, h_res, destination_path‌‌
    asset_to_export.export_material(name=asset_to_export.name,
                                    w_resolution=w_res,
                                    h_resolution=h_res,
                                    path=destination_path,
                                    subfolder=true,
                                    overwrite=true)


# Function to export as PNG with Unreal Engine 4 export preset
def export_as_png_with_blender_preset(asset_to_export, w_res, h_res, destination_path‌‌
    [blender_preset] = ssa.get_export_presets("Blender Cycles/Eevee")
    asset_to_export.export_material(name=asset_to_export.name,
                                    w_resolution=w_res,
                                    h_resolution=h_res,
                                    path=destination_path,
                                    format=ssa.jpg,
                                    preset=blender_preset,
                                    subfolder=true,
                                    overwrite=true)

# Verify if the project is already saved to get its path
# if ssa.save_project():
# ssa.save_project()
# print("Project saved")

# Get all assets of your project in a list
all_project_assets = ssa.get_project_assets()
print(f"Found {len(all_project_assets)} assets...")

# Get the folder path of the project
export_path = os.path.dirname(ssa.get_project_path())
print(f"Exporting to {export_path}...")

# Go Through the list of all assets
for asset in all_project_assets:
    try:
        print(f"Exporting asset {asset.name} with resolution 1024x1024px as SBSAR...")
        # Export each asset with the resolution 2048x2048px next to the project file (.ssa)
        export_as_sbsar(asset, 1024, 1024, export_path)
    except Exception as e:
        print(f"failed: {e}")

    try:
        print(f"Exporting asset {asset.name} with resolution 1048x1048px as JPG with Blender Cycles/Eevee preset...")
        # Export each asset with the resolution 2048x2048px in a folder "textures" next to the project file (.ssa)
        export_as_png_with_blender_preset(asset, 1048, 1048, os.path.join(export_path, "textures"))
    except Exception as e:
        print(f"failed: {e}")

# else:
#     print("Save first your project") #, file=sys.stderr)

 

 

Results in this error:

Exporting all assets...

Found 50 assets...

Exporting to [...]/output/50_schlechteste_skaliert_output...

Exporting asset 1005001 with resolution 1024x1024px as SBSAR...

failed: name 'true' is not defined

Exporting asset 1005001 with resolution 1048x1048px as JPG with Blender Cycles/Eevee preset...

failed: name 'true' is not defined

EDIT: Okay, I have to write True with a capital letter in Python. Got it. Now I get this error:

failed: export_material(): incompatible function arguments. The following argument types are supported:

1. (self: substance_sampler.Asset, path: str, name: str = '', subfolder: bool = False, format: substance_sampler.MaterialExportFormat = , material_type: substance_sampler.MaterialType = , preset: substance_sampler.Resource = Resource(, lifespan=temporary), w_resolution: int = 0, h_resolution: int = 0, channels: List[str] = [], physical_ratio: bool = False, overwrite: bool = True, controller: substance_sampler.ExportController = None) -> str

 

Invoked with: ; kwargs: name='1005001', w_resolution=1048, h_resolution=1048, path='[...]/output/50_schlechteste_skaliert_output\\textures', format=, preset=Resource(filterDesc://blender cycles/eevee, lifespan=temporary), subfolder=True, overwrite=True