Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now