Skip to main content
ZangouR
Participating Frequently
August 16, 2023
Answered

Export only BaseColor using python script

  • August 16, 2023
  • 3 replies
  • 1144 views

Hi,

I'm working on a script to export maps from Sampler using python,

but I can't find a way to only export the BaseColor channel.
Actually it's exporting all of the outputs.

Here is a snippet from the script

Any suggestions? thanks 🙂

# Function to export as PNG with Blender export preset 
def export_as_png_with_blender_preset(asset_to_export, w_res, h_res, destination_path): 
    [blender_export_preset] = ssa.get_export_presets("Blender Cycles/Eevee") 
    asset_to_export.export(w_resolution=w_res, 
                           h_resolution=h_res, 
                           path=destination_path, 
                           format=ssa.png,
                           channels=BaseColor, 
                           preset=blender_export_preset) 

(It's hard to find this kind of info in the API documentation...)

This topic has been closed for replies.
Correct answer Cyril Dellenbach

Hi @ZangouR,

 

The issue comes from

channels=BaseColor

 

channels expects a list.

channels (List[str]) – list of channels. By default: all channels of current workflow

Therefore it should be 

channels=["basecolor"]

 

Best regards,

 

3 replies

ZangouR
ZangouRAuthor
Participating Frequently
September 22, 2023

Here is the working script so you can use it to batch export the Base Color maps, enjoy 😊

import substance_sampler as ssa 
import os 
import sys 
 
 
# Function to export as PNG with Blender export preset 
def export_as_png_with_blender_preset(asset_to_export, w_res, h_res, destination_path): 
    [blender_export_preset] = ssa.get_export_presets("Blender Cycles/Eevee") 
    asset_to_export.export(w_resolution=w_res, 
                           h_resolution=h_res, 
                           path=destination_path, 
                           format=ssa.png,
                           channels=["basecolor"],
                           preset=blender_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 in a folder "textures" next to the project file (.ssa) 
        export_as_png_with_blender_preset(asset, 2048, 2048, os.path.join(export_path, "textures")) 
else: 
    print("Save first your project", file=sys.stderr) 
Participating Frequently
September 22, 2023

Thank you. When I add a script and call it via the script drop down menu nothing start. Even the demo script from Adobe does not start. I have Pyhon installed but I guess SA use its own Pyhon interpreter. Could you help me with this in order to make sure SA read and execute my installed script correctly ? Thank you

ZangouR
ZangouRAuthor
Participating Frequently
September 22, 2023

The script will export the maps to a folder called "textures", in the same directory as the .ssa project file.

Cyril Dellenbach
Community Manager
Cyril DellenbachCommunity ManagerCorrect answer
Community Manager
August 23, 2023

Hi @ZangouR,

 

The issue comes from

channels=BaseColor

 

channels expects a list.

channels (List[str]) – list of channels. By default: all channels of current workflow

Therefore it should be 

channels=["basecolor"]

 

Best regards,

 

Cyril Dellenbach (Micro) | QA Support Artist | Adobe
ZangouR
ZangouRAuthor
Participating Frequently
August 23, 2023

Hi Cyril,

Thank you so much, much appreciated 🙏

ZangouR
ZangouRAuthor
Participating Frequently
August 23, 2023

It worked, with a minor correction

channels=["basecolor"] instead of channels=["BaseColor"]

If someone is interested by the script I'll be happy to share it!

Cheers

Inspiring
August 22, 2023

ZangouR,

Sorry I don't have the answer... but I am having the same issue. Have you been able to export specific channels?  I would really like to find out  how to export texture maps without having to manually go through each material in a project which is cumbersome to say the least (and thats when Sampler doesnt crash when queuing up more than 4 or so texture sets!).

Better yet... an option within the Export panel to do this would be a pretty handy feature to say the least 😉