I’m trying to write a script to loop over the subtools and export them as a text file.
So far so good , except it will truncate at 255 bytes with about 30 subtools and long names. I’ve increased the memsize to no avail. I also tried to write each line at at time, to no vail.
I’ve also taken a look at Marcus’ write to file script and able to save a text file that’s over that amount. I’m not sure how much you can allocate as text and then dump to a file.
// Loop over all subtools,
// Grab subtool name, write to file
[VarDef, myWriteStr, “”]
[VarDef, memOffset, 0]
[VarDef, myBytes, 0]
[VarDef, newLine, [StrMerge, [StrFromAsc, 13], [StrFromAsc, 10]]] //
[VarDef, myFilePath, “”]
[VarDef, myFileName, “subtools.txt”]
[RoutineDef, WriteMem,
[MemResize, ZB_TextOutputMem, [MemGetSize, ZB_TextOutputMem] + 1024]
[VarSet, myBytes, [MemWriteString, ZB_TextOutputMem, pStr, memOffset, 0]]
[VarSet, memOffset, memOffset + myBytes]
[MemResize, ZB_TextOutputMem, memOffset]
, pStr]//end routine
[IButton, “Write subtools names”, “Writes out all sub tools names!”,
// create variable equal to number of sub tools
[VarDef, len, [SubToolGetCount]]
// DEFine the string
[VarDef, msg, “”] // Define it (once when script is loaded)
[VarSet, msg, “”] // set it at restart
[VarDef, tempStr, “”]
[VarSet, tempStr, “”]
// loop over array
[VarSet,i,0]
[Loop,len,
// select current sub tool
[SubToolSelect,[Val,i]]
// change subtoolName to the current subtool name
[VarSet, subtoolName, [IGetTitle,Tool:Subtool:Item Info]]
// shorten the string so it doesn’t have a . at the end
[VarSet, subtoolName, [StrExtract, subtoolName, 0, [StrLength, subtoolName]-2]]
// set the message to concatenate
[VarSet, msg, [StrMerge, msg, subtoolName, newLine]]
[VarSet, tempStr, [StrMerge, tempStr, subtoolName, newLine]]
[VarInc, i] // i++
// write to file
[VarSet, myWriteStr, tempStr]
[RoutineCall, WriteMem, myWriteStr]
// write to file
//when done, write memblock to file…
[VarSet, myFilePath, myFileName] // path to file - this example will be in the same location as this zscript
[VarSet, lBytes, [MemSaveToFile, ZB_TextOutputMem, myFilePath, 1]] // will overwrite existing file
", myFileName], 2]
// show number of subtools
[Note, [StrMerge, "Number of subtools: ", i, "
", msg],2]
] // end button