• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Enable/Autorun plugin by parameter?

New Here ,
Nov 07, 2024 Nov 07, 2024

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

59

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 07, 2024 Nov 07, 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(
...

Votes

Translate

Translate
Community Expert ,
Nov 07, 2024 Nov 07, 2024

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines