ZBrushCentral

Question : ZBRUSH_ZSTARTUP variable not working

Hey Hoping someone might know why this doesn’t work. For some reason, I can only read the file names in the folder if I hardcode the folder name. If I use the variable it doesn’t work.

[RoutineDef, ListFiles,
	[VarSet, folderName, "C:\Program Files\Maxon ZBrush 2022\ZStartup\ZPlugs64\TrigonToolbox\ViewSets\Presets\DataFiles"]
	[VarSet, folderName, "ZBRUSH_ZSTARTUP\ZPlugs64\TrigonToolbox\ViewSets\Presets\DataFiles"]
	[VarSet,fileIndex,0]
	[VarSet,folderIndex,0]
	[VarSet,fileCount,[FileExecute,[Var,dllPath],"GetFileNumber",folderName]]

	[VarSet,err,[FileExecute,[Var,dllPath],"OpenFolder",folderName]]
	[If,err,[Note,"Error opening folder."][Exit]]
	//create a memblock to get the file name
	[MemCreate,ZFileUtils_list, 256, 0]

	[Loop,fileCount,
		[VarSet,err,[FileExecute,[Var,dllPath],"GetFile",,,ZFileUtils_list]]  
		[If,err,[LoopExit]]

		[MemReadString, ZFileUtils_list,fileName]
		[VarSet,isaFile,0]
		[RoutineCall,CheckIsFile,isaFile,fileName]

		[If,isaFile,
			[VarSet, gFileList(n), fileName]
		]
	,n]

	[MemDelete,ZFileUtils_list]
	[VarSet,err,[FileExecute,[Var,dllPath],"CloseFolder",folderName]]
,folderName]

When I run it with just the first VarSet folder the hardcoded one it works. If I just do it with the second one it doesn’t work.

But all the other stuff I script this way is working fine for example

[RoutineCall, WriteTextToFile, [StrMerge, “ZBRUSH_ZSTARTUP\ZPlugs64\TrigonToolbox\ViewSets\Presets\DataFiles”, working, “.txt”]]

Is working fine it’s creating the file where it should be

Still stuck on the issue. I tried to fix it by writing the path to a text file. So I could read the path from the file. But it comes out as “Binary”

[VarDef, fUserSettings, "ZBRUSH_ZSTARTUP\ZPlugs64\TrigonToolbox\ViewSets\Data\UserSettings.txt"]
[VarDef, pUserPresets, "ZBRUSH_ZSTARTUP\ZPlugs64\TrigonToolbox\ViewSets\Presets"]

[RoutineDef, CreateUserSettings,
  [RoutineCall, WriteTextLineToFile, fUserSettings, pUserPresets]
]

[RoutineCall, CreateUserSettings]

and here is the routine

[RoutineDef,WriteTextLineToFile,
	[MemDelete, ZB_TextOutputMem]//just makes sure this isn't around
	[MemCreate,ZB_TextOutputMem,256]//create memblock	
	[VarSet,gOffset,0]
	[VarSet,gBytes,0]	
	
	[Loop, [VarSize, gStringList],
		[If, [StrToAsc, gStringList(n)] == 0,
			[LoopExit]
			,
			[VarSet,gWriteStr,[StrMerge,lineToWrite,#gNewLine]]
			[RoutineCall,WriteMem,#gWriteStr]
		]
	,n]

	[VarSet,lBytes,[MemSaveToFile,ZB_TextOutputMem,toFile,1]]//will overwrite existing file
	[MemDelete, ZB_TextOutputMem]
,toFile, lineToWrite]

Again the startup variable seems to work fine to the path to create the file. As it creates the file. But it’s refusing to write the path out. It comes out as "Binary"


Inside the text file:

0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 9732 c267 0026 0080

don’t know if understood the problem, but you seem to need that : [FileNameResolvePath,“ZBRUSH_ZSTARTUP\ZPlugs64\TrigonToolbox\ViewSets\Data\UserSettings.txt”]

[IButton,test,“test”,

[VarDef, userFile0, “ZBRUSH_ZSTARTUP\ZPlugs64\TrigonToolbox\ViewSets\Data\UserSettings.txt”]

[Note,userFile0]

[VarDef, userFile1, [FileNameResolvePath,“ZBRUSH_ZSTARTUP\ZPlugs64\TrigonToolbox\ViewSets\Data\UserSettings.txt”]]

[Note,userFile1]

]

1 Like

Man I can’t begin to thank you enough haha. I’ve been trying to fix this issue for the last 2 days. I still don’t understand how exactly it works tho. Could you perhaps explain it to me a bit if you know haha.

So far as I understand the [FileNameResolvePath] is converting local variable “ZBRUSH_ZSTARTUP” to the actual path

Because when I put the var like this it works

[VarDef, pUserPresets, [FileNameResolvePath,“ZBRUSH_ZSTARTUP\ZPlugs64\TrigonToolbox\ViewSets\Presets\DataFiles”]]

But when I put it like this it won’t work

[VarDef, pUserPresets, "ZBRUSH_ZSTARTUP\ZPlugs64\TrigonToolbox\ViewSets\Presets\DataFiles"]

While I define the path to the ZFileUtils64 like this which works. Togheter with a lot more file paths I define without the [FileNameResolvePath]

[VarSet, dllPath, [StrMerge, "ZBRUSH_ZSTARTUP\ZPlugs64\TrigonToolbox\", uiDllPath, "\ZFileUtils64.dll" ]]
[VarDef, fUSerSettings, "ZBRUSH_ZSTARTUP\ZPlugs64\TrigonToolbox\ViewSets\Data\UserSettings.txt"]

If you know why it works all the time without and this one time not without. I appreciate it a lot. Althouh no worries if you don’t know either or the question is vague. As I got the code working with your help!

1 Like

I’m not an expert. Maybe Marcus have an answwer to this. I can’t be 100% sure about the dll, maybe it have a function to evaluate the path internally.
image

After the FileNameResolvePath, note that there’s a / instead of a \ after the resolve with FilenameResolvepath, the Memsavetofile/MemReadString seems tolerant enough to make it work nonetheless.