Page 1 of 1
Posted: 02 Mar 2011, 22:07
by moody33
Hi again !
I need a script that could save an array to a text file, and another one that could perform the same process in reverse. So , the second one should open a txt file containing an array and extract those array to an array output. Both scripts have to read/write a large amount of array ( near 40 000 elements values) . The second one have to extract the array in one bloc size, ( should not extracts elements by an index).
Since senso have build a cool OpenDialog module, this script should be useful for everyone, and especially for me !
So, if there is any candidate ( follow my eyes

), I 'll be very happy !
Bisette.
Posted: 02 Mar 2011, 23:25
by bsork
I made a couple of scripts years ago that partly do what you want, you find them in the add-ons/data tools: data2textfile and textfile2data. These are however using the old scripting engine, so I think it's about time I revised them, I guess...
Anyone feel free to update them, I wont have time to do anything with them before the weekend.
Posted: 03 Mar 2011, 00:04
by senso
As I can remember there is a script in the /modules/scripts which does the job (inspired from the bsork script)
Posted: 03 Mar 2011, 01:15
by moody33
@senso
i've already take a look at the script, but it doesn't seems to correspond to my need since there is no inputs and no ouputs, I don't really understand how to use it.
@Bsork
If you have the time, I'll be happy if you make another one of course. I've already take a look to your former text to data and it seems to content errors ( show in the console ). And it only ouput one value at a time. So , I will wait for another one if possible.

Posted: 03 Mar 2011, 08:35
by bsork
I'll see what I can do during the weekend. I'm not at all surprised that the old script gives errors, as a lot has happened to Usine and the scripting engine since it was made.
Posted: 09 Mar 2011, 23:16
by moody33
Up...( and down ! )
Posted: 10 Mar 2011, 07:52
by bsork
Sorry to be late, but I've sidetracked myself with testing various script-stuff to improve file error handling and string manipulations. I will upload usable scripts without the extra touches tonight.
I haven't actually decided exactly what the extra touches would be either, so new add-ons will have to wait.
Posted: 10 Mar 2011, 22:50
by bsork
Here is a combined script for reading and writing arrays in text files. No fancy stuff, the only check being a FileExists before reading. Hopefully useful.
Code: Select all
VAR pArrayIn : TParameter;
VAR pArrayOut : TParameter;
VAR pFileName : TParameter;
VAR pWrite : TParameter;
VAR pRead : TParameter;
PROCEDURE Init;
BEGIN
pArrayIn := CreateParam('array in', ptArray); SetIsOutput(pArrayIn, FALSE);
SetMin(pArrayIn, -1000000); SetMax(pArrayIn, 1000000);
pArrayOut := CreateParam('array out', ptArray); SetIsInput(pArrayOut, FALSE);
SetMin(pArrayOut, -1000000); SetMax(pArrayOut, 1000000);
pFileName := CreateParam('file name', ptTextField); SetIsOutput(pFilename, FALSE);
pWrite := CreateParam('write', ptButton); SetIsOutput(pWrite, FALSE);
pRead := CreateParam('read', ptButton); SetIsOutput(pRead, FALSE);
END;
PROCEDURE Callback(n : Integer);
VAR i : Integer;
VAR list : TStringList;
BEGIN
CASE n OF
pWrite : BEGIN
list := TStringList.Create;
FOR i := 0 TO (GetLength(pArrayIn) - 1) DO
list.Add(FloatToStr(GetDataArrayValue(pArrayIn, i)));
list.SaveToFile(GetStringValue(pFileName));
list.Free;
END;
pRead : IF (FileExists(GetStringValue(pFileName))) THEN BEGIN
list := TStringList.Create;
list.LoadFromFile(GetStringValue(pFileName));
SetLength(pArrayOut, list.Count);
FOR i := 0 TO (list.Count - 1) DO
SetDataArrayValue(pArrayOut, i, StrToFloat(list[i]));
list.Free;
END
ELSE
WriteLn('Couldn''t open file: ' + GetStringValue(pFileName));
END;
END; // Callback
Posted: 10 Mar 2011, 23:21
by moody33
Really nice Bsork ! I 'll take a look asap.
Hope you had fun writing it !
Thanks you very much.