//ZFileUtils test zscript by Marcus Civis - September 2012 //The ZFileUtils.DLL and ZFileUtils.lib are provided 'as is' with no warranty of any kind - use at your own risk! //load this file through the ZScript:Load button //then press 'H' so that the buttons are visible at the bottom of the ZBrush interface //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~VARIABLES //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [VarDef,isMac,0]//do we have a Mac or PC [VarDef,Zvers,0]//ZBrush version [VarDef,dllPath,""]//plugin DLL path [VarDef,dllVersion,0]//plugin DLL version [VarDef,err,0]//standard error [VarDef,folderName,""]//folder path/name [VarDef,fileName,""]//file path/name [VarDef,fileCount, 0] // Number of files loaded [VarDef,copyFileName, ""] // Name of file to copy to [VarSet,index,0] //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~ROUTINES //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //The CheckSystem routine is a standard routine to make sure everything is as it should be. //You need to call it at the beginning of each button to make sure that the 'dllPath' variable is defined //If you don't get any errors but the code isn't working you probably forgot to call this! [RoutineDef, CheckSystem, //check ZBrush version [VarSet,Zvers,[ZBrushInfo,0]] [If,[Val,Zvers] >= 4.4,, [Note,"\Cff9923This zscript\Cffffff is not designed for this version of \Cff9923ZBrush\Cffffff.",,3,4737096,,300] [Exit] ] [VarSet,isMac, [ZBrushInfo,6]] //check Mac or PC // Make sure we have the dll and set its path [If,isMac, //use the path below for testing only [VarSet,dllPath,"MyPluginData/ZFileUtils.lib"] //use the path below for installed plugins //[VarSet,dllPath,"ZSTARTUP_ZPLUGS/MyPluginData/ZFileUtils.lib"] , //use the path below for testing only [VarSet,dllPath,"MyPluginData\ZFileUtils.dll"] //use the path below for installed plugins //[VarSet,dllPath,"ZSTARTUP_ZPLUGS\MyPluginData\ZFileUtils.dll"] ] [If, [FileExists, [Var,dllPath]], //check that correct version [VarSet, dllVersion, [FileExecute, [Var,dllPath], Version]] [If, [Val,dllVersion] >= 2.2,//dll version //OK ,//else earlier version [Note,"\Cff9923Note :\Cc0c0c0 The \Cff9923 ZFileUtils plugin \CffffffDLL\Cc0c0c0 is an earlier version which does not support this plugin. Please install correct version."] [Exit] ] , // else no DLL. [Note,"\Cff9923Note :\Cc0c0c0 The \Cff9923 ZFileUtils plugin \CffffffDLL\Cc0c0c0 could not be found at the correct location. Please re-install the plugin, making sure the relevant files and folders are in the \CffffffZStartup/ZPlugs\Cc0c0c0 folder."] [Exit] ] ]//end routine [RoutineDef,CheckIsFile,//routine to check if it's a file (not a folder) [VarSet,isF,0] [VarSet,fileExt,""] [If,([StrLength,file]>2),//we'll assume the file name is at least 2 chars [VarSet,fileExt,[FileNameExtract,file,4]]//and the file has an extension [If,[StrLength,fileExt],[VarSet,isF,1]] ] ,isF,file] [IButton,BatchObj,"Select .obj files", [RoutineCall,CheckSystem] //text for the dialog title (optional) [VarDef,dialogTitle, "Please select some files"] //string containing file extensions separated by commas(,) //if not used then all files will be used [VarSet,fileExt,"obj,GoZ,ma"] //create memblock for file extensions [MemCreate,ZFileUTils_FileExt, 256, 0] //copy file extensions to memblock [MemWriteString,ZFileUTils_FileExt,fileExt,0] //create and launch Open File dialog //returns the number of files selected [VarSet, fileCount, [FileExecute, [Var,dllPath],"GetFilesDialog",#dialogTitle,,ZFileUTils_FileExt]] //***alternative GetFilesDialog function call with no title text or file extensions: //[VarSet, fileCount, [FileExecute, [Var,dllPath], "GetFilesDialog"]] //delete the memblock as we've finished with it [MemDelete,ZFileUTils_FileExt] //display the number of files selected [Note,[StrMerge,fileCount," files selected"],,2] //now get the full file path to each file selected [If,fileCount > 0, //Create a memblock to get the file path [MemCreate,Test_ZFileUTils, 256, 0] //get each of the file paths [VarSet,index,1] [Loop,fileCount, [VarSet,err,[FileExecute, [Var,dllPath],GetFilePath,,index,Test_ZFileUTils]] [VarInc,index] //if all is OK copy from memblock to variable [If,err == 0, [MemReadString, Test_ZFileUTils, fileName] [FileNameSetNext, fileName][IPress,Tool:Import] [IPress,Tool:Display Properties:Flip] [ISet,Tool:Deformation:Polish,100] [FileNameSetNext,"/users/Shared/ZBrushData/Temp/objIn.goz"][IPress,Tool:Geometry:ZRemesher] [FileNameSetNext, fileName][IPress,Tool:Export] //do stuff //display the file name and path [Note,fileName,,1] , [LoopContinue] ] ]//end loop [MemDelete,Test_ZFileUTils] ]//end if fileCount ]//end button