Skip to main content
Participant
November 7, 2024
Answered

Enable/Autorun plugin by parameter?

  • November 7, 2024
  • 1 reply
  • 218 views

Hi,

 

is there any option within SD/Python to enable or trigger execution of plugins by parameter or other trigger?

 

What I want to achieve: I have a plugin (currently using some application callbacks) that I would only like to use to some automation, not when using it the "normal way" (working on graphs). My current workaround is to use a lock file (could also use a system variable, I guess). 

 

Would be nice to have a more decent control over the parameter i.e. auto-cleaning after SD quits insteads of bash-script to release the lock file (or system variable).

 

Any ideas? Thanks!

This topic has been closed for replies.
Correct answer Marco Vitale

Hey xray3,

I'm not sure if that is what you are looking for, but you could use a separate thread, which runs a loop, where you can do your checks you could either start the thread manually or even automate it by using the initializeSDPlugin() method, make sure you properly exit the thread using the uninitializeSDPlugin() method (although I think the thread is destroyed anyway, when SD closes, because the python environment gets closed)

 
from PySide6.QtCore import QThread, QTimer

class Worker(QThread):
    def __init__(self, timeout: int):
        super().__init__()
        self.timeout = timeout
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.loop)
        self.timer.start(self.timeout)

    def loop(self):
        # THIS IS THE LOOP, WHERE YOU CAN DO YOUR AUTOMATION TASKS
        pass

    def run(self):
        self.loop_count = 0
        self.exec()

# USAGE
def initializeSDPlugin():
    global worker
    worker = Worker(1000)  # SET THE TIME IN MILLISECONDS
    worker.start()

def uninitializeSDPlugin():
    global worker
    worker.exit()

 

Stay healthy and creative Marco

1 reply

Marco VitaleCommunity ExpertCorrect answer
Community Expert
November 8, 2024

Hey xray3,

I'm not sure if that is what you are looking for, but you could use a separate thread, which runs a loop, where you can do your checks you could either start the thread manually or even automate it by using the initializeSDPlugin() method, make sure you properly exit the thread using the uninitializeSDPlugin() method (although I think the thread is destroyed anyway, when SD closes, because the python environment gets closed)

 
from PySide6.QtCore import QThread, QTimer

class Worker(QThread):
    def __init__(self, timeout: int):
        super().__init__()
        self.timeout = timeout
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.loop)
        self.timer.start(self.timeout)

    def loop(self):
        # THIS IS THE LOOP, WHERE YOU CAN DO YOUR AUTOMATION TASKS
        pass

    def run(self):
        self.loop_count = 0
        self.exec()

# USAGE
def initializeSDPlugin():
    global worker
    worker = Worker(1000)  # SET THE TIME IN MILLISECONDS
    worker.start()

def uninitializeSDPlugin():
    global worker
    worker.exit()

 

Stay healthy and creative Marco