ZBrushCentral

Loop through files in folder and sub-folders

Hello,

I just learned from my co-worker that I need to remesh 934 objects with a crappy topology (scanned objects) for next week. Yay.

As there is no way I’m cleaning these objects one by one, I want to create a Zscript allowing me to import an object, do a dynamesh to clean holes and n-gones, a ZRemesher to have a nice quad mesh, then re-export it as an OBJ.

(Well, it will be a bit more complicated as I need to export a low-def, mid-def and high-def version of each object, but one thing at a time…)

I’m a bit familiar with scripting, but not with ZScript. I see perfectly what I need to do, except I can’t figure out how to loop through a folder’s content. All my OBJs are stored in subfolders, and I need to open them one at a time. Is there a way to fill a list with all the OBJs fullpaths and loop through it, given the top folder name ?

Thanks in advance !

(sorry for mistakes, I’m french)

You could record a macro and then save it, then open it up in your editor of choice (I use the Crimson Editor) however there are issues. One script can’t call a plug-in and keep working afterwards. http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/command-reference/#Variables
See also as it may be able to help you in some way.>> http://www.zbrushcentral.com/showthread.php?172391-Useful-small-ZScripts-and-Macros-for-ZBrush-4R6&p=1051377&viewfull=1#post1051377

See also>> http://www.zbrushcentral.com/showthread.php?172426-multi-obj-importer-is-there-a-way-for-it-to-work-with-ZB4r4p2&p=980264&viewfull=1#post980264

You’ll need to use the ZFileUtils dll in order to get a list of files from a folder (and this won’t act recursively on sub-folders):

http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/zfileutils/#listFolder

Alternatively you can get zscript to read a text file line by line and get the paths to the files that way, if you had some way to write the text file first!

http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/

HTH,

Thanks for your answers :slight_smile:

I already tried ZFileUtils, but didn’t manage to understand how it worked, and I didn’t want to lose time on it… The text file with the paths is another solution indeed, I think I may use it.

Doug Jones, on one of the threads you provided, I learned about the multiAppend function of SubTool Master. For now, I will try to import groups of objects with that, and loop my script on each subtool to see if it works. And if I have the time, I’ll try to include the solution mentioned by marcus_civis.

Thanks again for your help, both of you !

Hello again,

My script is done, but I can only use it folder by folder… and it’s slow…

Marcus_civis, I searched through the doc, but I didn’t find information on opening and reading a text file with Zscript. Do you have a link where I could learn about it (or the name of the chapter in the doc ? Maybe I missed it…) ? I have a text file filled with each object full path, how can I loop through it ?

Thanks in advance

There’s no tutorial as such but you use the memory block commands. Attached is an example. You’ll need to edit it to suit your requirements.

One thing to bear in mind is the way ZBrush imports OBJs. If you have a model selected that has no subdivision levels then importing an OBJ will replace that model. However, the imported OBJ will take on the scale and offset of that model (as in the Tool>Export sub-palette), which you may not want. What Isuggest you do is:

  1. Save out the PolyMesh3D (Star) as a ZTL.
  2. Every time you want to import an OBJ, first load in the ZTL you saved at (1).

That way your OBJs will come in at the correct scale and offset, and will be OK when you export them again.

Also, you can use

[IKeyPress,13,[IPress,Preferences:Init ZBrush]]

to clear the tools from the Tool palette so that there are not too many. (The IKeyPress,13 simulates pressing enter so that you don’t get a dialog box when initializing ZBrush.)

HTH,

I’ve edited the script as I had forgotten to delete the memory block when it was finished with.

That’s perfect ! I finally managed to batch clean all those OBJs (and learn a bit more about Zscript) ! Thank you for your kind help !

As I didn’t have to change the scale or position of my objects, I didn’t implement the system you talked about, but it may be useful for next time ! I’m still a beginner at Zbrush too, so those tips are good to know !

Great. :slight_smile: I’m glad it was useful.