Skip to content

Instantly share code, notes, and snippets.

@BigRoy
Created January 11, 2023 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BigRoy/782b85755de08b1ebe19c7aea7e30615 to your computer and use it in GitHub Desktop.
Save BigRoy/782b85755de08b1ebe19c7aea7e30615 to your computer and use it in GitHub Desktop.
Get Adobe Substance 3D Painter export maps from an export preset by filename template to filename
import substance_painter.resource
import substance_painter.js
import tempfile
def get_export_maps(preset, folder=None, format="exr"):
"""Return filenames from export preset by filename template.
Note: This doesn't return each individual UV tile.
"""
strip_folder = folder is None
if folder is None:
folder = tempfile.gettempdir()
folder = folder.replace('\\', '/')
cmd = f'alg.mapexport.getPathsExportDocumentMaps("{preset}", "{folder}", "{format}")'
result = substance_painter.js.evaluate(cmd)
if strip_folder:
# Strip off the folder
for _stack, maps in result.items():
for fname_template, fname in maps.items():
# Strip folder
assert fname.startswith(folder)
fname = fname[len(folder)+1:]
maps[fname_template] = fname
return result
if __name__ == "__main__":
for stack, maps in get_export_maps("Arnold (AiStandard)").items():
print(f"stack: {stack}")
for template, fname in maps.items():
print(f"{fname_template: <60} -> {fname}")
@BigRoy
Copy link
Author

BigRoy commented Jan 11, 2023

Example output:

stack: DefaultMaterial
$mesh_$textureSet_Roughness(_$colorSpace)(.$udim)            -> test_local_asset1_pointcacheMain_v004_DefaultMaterial_BaseColor_ACES - ACEScg.1002.exr
$mesh_$textureSet_Roughness(_$colorSpace)(.$udim)            -> test_local_asset1_pointcacheMain_v004_DefaultMaterial_Emissive_ACES - ACEScg.1002.exr
$mesh_$textureSet_Roughness(_$colorSpace)(.$udim)            -> test_local_asset1_pointcacheMain_v004_DefaultMaterial_Height_Utility - Raw.1002.exr
$mesh_$textureSet_Roughness(_$colorSpace)(.$udim)            -> test_local_asset1_pointcacheMain_v004_DefaultMaterial_Metalness_Utility - Raw.1002.exr
$mesh_$textureSet_Roughness(_$colorSpace)(.$udim)            -> test_local_asset1_pointcacheMain_v004_DefaultMaterial_Normal_Utility - Raw.1002.exr
$mesh_$textureSet_Roughness(_$colorSpace)(.$udim)            -> test_local_asset1_pointcacheMain_v004_DefaultMaterial_Roughness_Utility - Raw.1002.exr

Result as JSON:

{
    "DefaultMaterial": {
        "$mesh_$textureSet_BaseColor(_$colorSpace)(.$udim)": "test_local_asset1_pointcacheMain_v004_DefaultMaterial_BaseColor_ACES - ACEScg.1002.exr",
        "$mesh_$textureSet_Emissive(_$colorSpace)(.$udim)": "test_local_asset1_pointcacheMain_v004_DefaultMaterial_Emissive_ACES - ACEScg.1002.exr",
        "$mesh_$textureSet_Height(_$colorSpace)(.$udim)": "test_local_asset1_pointcacheMain_v004_DefaultMaterial_Height_Utility - Raw.1002.exr",
        "$mesh_$textureSet_Metalness(_$colorSpace)(.$udim)": "test_local_asset1_pointcacheMain_v004_DefaultMaterial_Metalness_Utility - Raw.1002.exr",
        "$mesh_$textureSet_Normal(_$colorSpace)(.$udim)": "test_local_asset1_pointcacheMain_v004_DefaultMaterial_Normal_Utility - Raw.1002.exr",
        "$mesh_$textureSet_Roughness(_$colorSpace)(.$udim)": "test_local_asset1_pointcacheMain_v004_DefaultMaterial_Roughness_Utility - Raw.1002.exr"
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment