Skip to main content
Participant
November 7, 2023
Question

Is there a way to detect when an application has completed loading with API?

  • November 7, 2023
  • 0 replies
  • 96 views

Is there a way to detect when an application has completed loading?

 

I am developing my own plugin to determine if all shelf resources have been loaded, but when I run this process in start_plugin(), the plugin does not complete loading and the application does not finish loading.

 

Therefore, I need to trigger this process on the application load completion event.

I can detect that the project has been loaded with substance_painter.event.ProjectOpened(), but I could not find an event to detect the application loading.

 

I would appreciate any suggestions for a better solution.

 

[sample code]

import os
import time
import re
import substance_painter

def check_shelf_is_loaded(root_dir="shelf_reference_path", max_limit=90) -> bool:
    """This returns True if loading of all resources in specific shelf has completed."""
    src_resource_count = sum(os.path.isfile(
        os.path.join(root_dir, name)) for name in os.listdir(root_dir))
    
    dst_resource_count = len(get_shelf_resources())
    for i in range(1, max_limit, 1):
        if src_resource_count <= dst_resource_count:
            print("load time: {}sec".format(i))
            return True
        time.sleep(1)
    return False

def get_shelf_resources(pattern="some_matching_pattern") -> list:
    for i in substance_painter.resource.Shelves.all():
        res = re.match(pattern, i.name())
        if res:
            return i.resources()
    return []

def start_plugin():
    check_shelf_is_loaded() # <= can't complete application loading...

 

This topic has been closed for replies.