I have been investigating how to get the current zbrush project filepath the artist is working in from script, but can’t find it.
Since Zbrush 2023 it seems the File menu has also now gotten a File > Save Next option which makes it clear that Zbrush does track the current or last project path that was set in the current session - as such, it sounds like Zbrush is storing that somewhere in a memory block.
Is there any chance we can read the current zbrush project path from the memory block with an identifier or get it in a different manner?
Things I’ve tried:
Last file
The [FileNameGetLastUsed]
and [FileNameGetLastTyped]
commands seem to return any filepath that was loaded or exported, e.g. even scripts, .obj
exports, etc. and even though this does work directly after opening a .zpr
project file as soon as you load a new file into the current project or export something this does not refer to the current project file anymore.
Main or Active tool is not the same
Note that [GetMainToolPath]
and [GetActiveToolPath]
don’t suffice since they relate to the tool being active, not the current project. I’m looking for the current .zpr
.
Storing a string in a memory block
I understand I can implement a custom save button that writes my own data into memory, e.g. along the lines of:
// Create a memory block to hold the filepath
[MemDelete, MyCurrentFilePath] // Delete if it already existed
[MemCreate, MyCurrentFilePath, [StrLength, "{workfile_path}"]]
[MemWriteString, MyCurrentFilePath, "{workfile_path}"]
But admittedly that would just be a workaround for not being able to get the project path from the Zbrush session. It’d still require a user to always use my custom save button/script.
File:Current File
Unlike [IGetTitle, Tool:Current Tool]
there doesn’t seem to be a File
menu equivalent, each of these fail:
[IGetTitle, File:Current File]
[IGetTitle, File:Current]
[IGetTitle, File:Current Project]
[IGetTitle, File:Current]
[IGetTitle, File:ItemInfo]
This topic describes using e.g. Tool:ItemInfo
but there doesn’t seem to be a File:
equivalent either.
Get recent file from the Lightbox
I can get the local zbrush data folder:
[FileNameResolvePath, ZPUBLIC_]
Which resolves to for example:
C:\Users\Public\Documents\ZBrushData2024\
From there I could e.g. parse the recent files from the Lightbox:
import os
def get_last_recent_project():
data = r"C:\Users\Public\Documents\ZBrushData2024" # this would be returned by [FileNameResolvePath, ZPUBLIC_]
recent_files_cfg = os.path.join(data, "ZStartup", "ConfigFiles", "LightboxRecentFiles.cfg")
with open(recent_files_cfg, "r") as f:
paths = f.read().split('\x00') # split on null bytes
for path in paths:
if path.lower().endswith(".zpr"):
# Path is a zproject file
return path
print(get_last_recent_project())
But still, quite a hack - and the most recent file might not even be loaded into the current session. It could be from another zbrush session.