Skip to main content
Participant
April 10, 2023

startup.py not working

  • April 10, 2023
  • 4 replies
  • 502 views

When trying to use Python to build a Project file I can execute these two lines in the script panel, everything works fine. However, when I put this code into a startup.py in the startup folder of SUBSTANCE_PAINTER_PLUGINS_PATH, it does not work.

 

import substance_painter.project
substance_painter.project.create(mesh_file_path="D:/Temp/box_low.fbx")

 

The fbx file is a simple cube. But, this does not work wuth any fbx file I use. Here is the full startup.py code:

import substance_painter.logging
import substance_painter.project

def start_plugin():
    """This method is called when the plugin is started."""
    logger = substance_painter.logging.info

    logger("Substance Painter started")
    substance_painter.project.create(mesh_file_path="D:/Temp/box_low.fbx")

def close_plugin():
    """This method is called when the plugin is stopped."""
    pass

if __name__ == "__main__":
    start_plugin()

Upon startup I get the logger message, but nothing else.

4 replies

Known Participant
July 19, 2023

I am having some issues with this workaround though, as it appears that I get multiple calls for this. So my startup script then triggers more than once? 

Have I missunderstood this please? - And are there any alternative ways to achive this also please. 

Thanks for your time! 

def start_plugin():
    print ("AltStart : Loading : Start")
    sp_event.DISPATCHER.connect(sp_event.ShelfCrawlingEnded, status_PainterLoaded_callback)  # substance_painter.event.ShelfCrawlingEnded --- Use this to waite for painter to load
    

def status_PainterLoaded_callback (any): 
    print ("AltStart : Loading : Done") # It looks like this is calling multiple times, this must only call once! 
    Open_Project()

 

Known Participant
July 19, 2023

Thanks, that helped with my issue for opening a project from startup too! 

 

Cyril Dellenbach
Community Manager
Community Manager
April 12, 2023

Hello @MH2k,

 

Following your discussion with the team and for the people who may have a similar issue:

 

Unfortunately, you cannot simply drop the plugin in the start up folder, because Substance 3D Painter won't be ready when the plugin is called.

 

We currently don't have a dedicated event for this, but the workaround is to call the substance_painter.event.ShelfCrawlingEnded event and then trigger the project creation, forcing Substance Painter to wait the end of the shelf's crawling before creating the project.

 

Best regards,

 

Cyril Dellenbach (Micro) | QA Support Artist | Adobe
MH2kAuthor
Participant
April 10, 2023

I even get the same nothingness when I try to run the lines through subprocess: 

import os
import subprocess

import substance_painter.logging

def start_plugin():
    """This method is called when the plugin is started."""
    logger = substance_painter.logging.info

    logger("Substance Painter started")
    script_file = "D:/TEMP/build_project.py"
    if os.path.exists(script_file):
        logger("Executing script file: {}".format(script_file))
        output = subprocess.run(["C:\\Python27\\python.exe", script_file])
        logger("Output: {}".format(output))

def close_plugin():
    """This method is called when the plugin is stopped."""
    pass

if __name__ == "__main__":
    start_plugin()

build_project.py: 

import substance_painter.project
substance_painter.project.create(mesh_file_path="D:/Temp/box_low.fbx")