Skip to main content
Participant
July 22, 2025
Answered

How do I set a layer's category via Python API?

  • July 22, 2025
  • 1 reply
  • 173 views

I am trying to use the API to automate processing of a directory containing some images. I need to set the category under the "basic parameters" section. How can this be accomplished?

 

 

Correct answer LoryAline

Hi, 
Here is how you can achieve that :

import substance_sampler as ssa

def main():
    asset = ssa.get_selected_asset()
    image_to_material_layer = asset.get_layers()[2]
    category_parameter = [l for l in image_to_material_layer.parameters if l.identifier == "category"][0]
    category_parameter.value = 0 # 0 for Ceramic => it is the index in the list of categories

if __name__ == '__main__':
    main()

If you are searching for other methods, you can consult the Python API documentation. Here is how to access it:

 

1 reply

LoryAline
Community Manager
LoryAlineCommunity ManagerCorrect answer
Community Manager
July 23, 2025

Hi, 
Here is how you can achieve that :

import substance_sampler as ssa

def main():
    asset = ssa.get_selected_asset()
    image_to_material_layer = asset.get_layers()[2]
    category_parameter = [l for l in image_to_material_layer.parameters if l.identifier == "category"][0]
    category_parameter.value = 0 # 0 for Ceramic => it is the index in the list of categories

if __name__ == '__main__':
    main()

If you are searching for other methods, you can consult the Python API documentation. Here is how to access it: