ZBrushCentral

how to load multiple mdd files to layers for different subtools

for example, I have a subtools contain three meshes, and a folder have obj or mdd for each of them, how can I load them as a layer to matched mesh? I found a similar tool - ImportLayers, but it will show error msg if you select the incompatible file.

thanks,

The straightforward way would be to match the file names to the subtools. If you can’t do that then you would need to compare the number of vertices, though note that if there are subtools with the same number of vertices then there’s no way to be sure the right file is loaded.

With OBJ, if it is from ZBrush then the number of vertices is given in a comment at the beginning of the file but this isn’t standard and OBJs from elsewhere would need to be parsed or imported separately to get the vertex count.

MDD files are simpler and the vertex count could be read from the start of the file.

got it, so where I can find the api for compare the vertex count ?

The zscript command reference is here:
http://docs.pixologic.com/user-guide/customizing-zbrush/zscripting/command-reference/

Here’s a way to do both types of file. But note that the OBJ example will only work with OBJs exported from ZBrush. To cope with other files you would need to either load them into ZBrush separately so you could check the vertex count that way or parse them using a dynamic library which you called from your zscript code.

IButton,CompareVertCountMDD,[COLOR=#f86b6b]“Check if the MDD file verts count is the same as selected mesh”,
VarSet,[COLOR=#c3dff9]fileVerts,0]
VarSet,[COLOR=#c3dff9]meshVerts,0]
//load the file 5th - 8th bytes into memory
MemCreateFromFile,[COLOR=#e1b8e1]MC_VertTestMem,[COLOR=#f86b6b]“boxing.mdd”,4,4]
MemCreate,[COLOR=#e1b8e1]MC_VertsLEMem,4,0]
//convert big endian to little endian:
MemCopy,[COLOR=#e1b8e1]MC_VertTestMem,3,[COLOR=#e1b8e1]MC_VertsLEMem,0]
MemCopy,[COLOR=#e1b8e1]MC_VertTestMem,2,[COLOR=#e1b8e1]MC_VertsLEMem,1]
MemCopy,[COLOR=#e1b8e1]MC_VertTestMem,1,[COLOR=#e1b8e1]MC_VertsLEMem,2]
MemCopy,[COLOR=#e1b8e1]MC_VertTestMem,0,[COLOR=#e1b8e1]MC_VertsLEMem,3]
//get the file verts number - unsigned long
MemRead,[COLOR=#e1b8e1]MC_VertsLEMem,[COLOR=#c3dff9]fileVerts,6,0]
//done with memblocks - delete
MemDelete,[COLOR=#e1b8e1]MC_VertTestMem]
MemDelete,[COLOR=#e1b8e1]MC_VertsLEMem]
//get the mesh verts number:
Mesh3DGet,0,[COLOR=#c3dff9]meshVerts]
If,([COLOR=#c3dff9]fileVerts == [COLOR=#c3dff9]meshVerts),
//OK they match
Note,[COLOR=#f86b6b]“OK, the verts number is the same”]
,//else they are different
Note,[COLOR=#f86b6b]“WARNING! the verts number is different”]
]
]

IButton,CompareVertCountOBJ,[COLOR=#f86b6b]“Check if the OBJ file verts count is the same as selected mesh”,
VarSet,[COLOR=#c3dff9]fileVerts,0]
VarSet,[COLOR=#c3dff9]meshVerts,0]
VarSet,[COLOR=#c3dff9]vertsStr,[COLOR=#f86b6b]""]
VarSet,[COLOR=#c3dff9]offset,0]
VarSet,[COLOR=#c3dff9]bytes,0]
//load first part of OBJ file into memory
MemCreateFromFile,[COLOR=#e1b8e1]MC_VertTestMem,[COLOR=#f86b6b]“boxing.obj”,0,512]
//check the comment lines for ZBrush vertex count entry
Loop,5,
VarSet,[COLOR=#c3dff9]bytes,MemReadString,[COLOR=#e1b8e1]MC_VertTestMem,[COLOR=#c3dff9]vertsStr,[COLOR=#c3dff9]offset,1]]
VarAdd,[COLOR=#c3dff9]offset,[COLOR=#c3dff9]bytes]
If,(StrFind,[COLOR=#f86b6b]"#Vertex Count ",[COLOR=#c3dff9]vertsStr]==0),//if entry is there
VarSet,[COLOR=#c3dff9]vertsStr,StrExtract,[COLOR=#c3dff9]vertsStr,14,256]]
VarSet,[COLOR=#c3dff9]fileVerts,[COLOR=#c3dff9]vertsStr]
LoopExit]
]
]
//get the mesh verts number:
Mesh3DGet,0,[COLOR=#c3dff9]meshVerts]
If,([COLOR=#c3dff9]fileVerts == [COLOR=#c3dff9]meshVerts),
//OK they match
Note,[COLOR=#f86b6b]“OK, the verts number is the same”]
,//else they are different
Note,[COLOR=#f86b6b]“WARNING! the verts number is different”]
]
]

thanks marcus, you are my hero again.
I uploaded the code and video here, hope you will be interested.

Looks great! :+1: Thanks for sharing.