ZBrushCentral

Question: how to read string from file and extract integer

Hello,
I want to do this thing, but not really understand how to do it on Zscripting, hope on your support guys, thanks

I want to read .txt file that have this looking:

model.obj 20
model2.obj 35
model3.obj 50

model1000.obj 20

here model.obj it’s name , and integer it’s ZRemesher:“Target polygon count”

I check forum and find how to do reading from txt file and importing this files, and apply ZRemesher, but i can’t understand how here working function working with string.
So question: how to extract from each line this integers (20,35,50,…,20) and setup them as Target polygon count parameter for each model

Thanks for reading!

You need to extract the substrings so you have the file name and the target count as separate strings. Then if the target count string is assigned to a number variable it is automatically cast as a number:

IButton,ReadFromFile,“Read from a text file”,
VarSet,gFilePath,“input.txt”]
If,FileExists,gFilePath],
//create memory block from the file
MemCreateFromFile,ZB_TextInputMem,gFilePath]
]
VarSet,gOffset,0]
VarDef,lStr,""]
VarDef,lTargetPolys,0]
If,MemGetSize,ZB_TextInputMem],
Loop,10000,
//read a line into a string variable
VarSet,gBytes,MemReadString,ZB_TextInputMem,lStr,gOffset,1]]
//find “obj”
VarSet,endPath,StrFind,“obj”,StrLower,lStr]]]
If,endPath > -1,//if “obj” found
//extract file path string
VarSet,lImportPath,StrExtract,lStr,0,endPath+2]]
//extract target polys string
VarSet,lTargetPolys,StrExtract,lStr,endPath+4,256]]
If,FileExists,lImportPath],
FileNameSetNext,lImportPath]
IPress,Tool:Import]
ISet,Tool:Geometry:Target Polygons Count,lTargetPolys]
IUpdate,1,1]//update the UI
IPress,Tool:Geometry:ZRemesher]
FileNameSetNext,lImportPath]
IPress,Tool:Export]
]
]
VarSet,gOffset,gOffset+gBytes]
If,gOffset >= MemGetSize,ZB_TextInputMem],LoopExit]]
]
]
MemDelete,ZB_TextInputMem] //all done, delete memblock
]

When i write this question i hope, that you Marcus will see it, thanks for your answer,help and time!