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

[Python Scripting] Writing Project Metadata when saving the project

New Here ,
Aug 04, 2022 Aug 04, 2022

Hello there!

I am currently experiencing some trouble while developing a python plugin for the newest Substance Painter version (8.1.2).

Lets say I want to save some string data from my plugin to the project file, when the project file is saved.

My current approach is to write that into the projects metadata, when the project is about to be saved, using the substance_painter.project and substance_painter.events module.

Consider the following pseudocode:

 

import substance_painter.events
import susbtance_painter.project

class PseudoClass:
    def __init__(self):
    ...
    self.event_dispatcher = substance_painter.events.DISPATCHER
    self.event_dispatcher.connect(substance_painter.events.ProjectAboutToSave, self.save_settings)
    ...

    def save_settings(self, event):
        metadata = substance_painter.project.Metadata("PluginSaveData")
        metadata.set("plugin_save_data", "testsavedata")

 

This should work in theory, but sadly raises the following Error instead:

[Python] File "C:\Program Files/Adobe/Adobe Substance 3D Painter/resources/python/modules\substance_painter\project.py", line 794, in set
_substance_painter.project.set_metadata(self._context + "/" + key, value)

[Python] _substance_painter.exception.ProjectError: The project is locked.

As far as my understanding goes that Error is raised before and after saving, so i could not attach it to any of the save events. (Trying to write metadata works neither in the "ProjectAboutToSave" nor using the "ProjectSaved" event

A workaround i tried is to attach the saving process to the "BusyStatusChanged" Event instead, but appereantly Painter doesn't count as "busy" when saving a file.
Using substance_painter.project.execute_when_not_busy() also doesnt work.

And with no more events left at my disposal, I came here to ask if anyone possibly has a solution.


Thanks a lot already for any replies!

TOPICS
Scripting
803
Translate
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
Adobe Employee ,
Aug 30, 2022 Aug 30, 2022

Hello,

 

Sorry for the late reply.

I have discussed a bit with the team about your request and use-case, and unfortunately right now we don't have a way to do what you want. I have logged that request and we are going to look into it.

Translate
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
New Here ,
Mar 11, 2025 Mar 11, 2025

Hello, to date (Subsatnce Painter 10.1.2) there is still no answer to this use case. Is there any way of implementing it in a future version of Painter?

Translate
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
New Here ,
Mar 13, 2025 Mar 13, 2025
LATEST

We had exactly the same problem during the execution of a code triggered by an event. We had to lock and unlock project manually to call some functions that triggered a ProjectError:

import _substance_painter.project as _sp_p
import substance_painter.project as sp_p
import substance_painter.event as sp_e

def on_project_saved(event):
    _sp_p.do_action(_sp_p.Action.Unlock)
    mesh_path = sp_p.last_imported_mesh_path()
    _sp_p.do_action(_sp_p.Action.Lock)
    print(mesh_path)

sp_e.DISPATCHER.connect(sp_e.ProjectAboutToSave, on_project_saved)

Hop this helps.

Translate
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