Skip to main content
Participant
July 14, 2023

Can't set values of a layer created from a threaded script

  • July 14, 2023
  • 2 replies
  • 271 views

Hello! I made a script that creates an asset, adds a layer and sets a layer's parameter. When it runs from the main thread, everything works. When I use threading, it doesn't set the parameter value. If I add a pause before the parameter setting, and manually select the created asset in the assets panel while the script is sleeping, it works.

App version: 3.4.1

Windows 10 x64

Steps to reproduce:

1. Run the script attached

Expected result: Created an asset BUG, layer Blur added, changed Intensity parameter value to 5

Actual result: default Intensity parameter value of 1

import time
import substance_sampler as ssa
import threading

def main():
    ssa.save_project()
    asset = ssa.create_asset('BUG', ssa.AssetType.material)
    parameter = 'Intensity'
    filter_name = 'Blur'
    filters = ssa.get_filters('')
    filter = next((x for x in filters if x.name == filter_name), None)
    asset.insert_filter(filter, 0)
    layer = asset.get_layers()[0]
    parm = next((x for x in layer.parameters if x.label == parameter), None)
# Uncomment this, start the script and select the created layer, it will work.
# time.sleep(5)
    if parm:
        parm.value = 5
        ssa.save_project()
    else:
        print(f'Parameter {parameter} not found in layer {layer.name}')
        
t = threading.Thread(target=main)
t.start()

 

 

2 replies

Participant
July 31, 2023

Hello,

i want to say that, the script works correctly when run from the main thread but encounters issues when using threading. Ensure that the Substance Sampler API functions used in the script are thread-safe. Consider synchronizing access with locks or semaphores if necessary. If the problem persists, check the API documentation or contact Substance Sampler support for guidance. Multithreading can introduce complexities, so implement it carefully.

Baptiste_Substance_3D
Community Manager
Community Manager
July 21, 2023

Hello,

We're looking at the issue. That is not something we have tested.

We have a plugin example here that uses Threading:

https://helpx.adobe.com/substance-3d-sampler/scripting-and-development/create-a-plugin-with-python-and-qml.html