Message 1 of 15
Manipulate .csv through MaxScript?

Not applicable
09-17-2012
08:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
i'm trying to make a (my first) maxscript wich allows me to import a .csv file as an animated timeline with some interaction from the user.
My .csv is built up per line as follows:
,,,,,,,,,
In this line the and all the following values are irrelevant to me. I've attached an example of the .csv file.
What I want to accomplish is that the MaxScript evaluates the second line in the .csv file(the first contains headers) and calculates the total duration of the Task.
I.e: #,Total_Planning,#,#,#,#,#,27-9-2012 5:00,2-10-2012 2:00,Construct
- So the total construction time would be 117 hours. This is easy for us to calculate, but is there a way to let MaxScript do this? Taking into account that the months do not always contain the same amount of days.
What I'm trying to avoid is to manipulate the .csv file myself.
I know excel can calculate the difference but can MaxScript start/call this function? (As I'm trying to avoid altering the .csv file myself)
This calculation is needed multiple times where the resulting values will be used as variables for different things, therefor I want to use MacScript. So far I haven't come further then defining the variables based on a filterstring.
I'm also curious about a way of coping with empty values in the .csv file.
Any help would be appreciated.
PS. I know the numbers for the string filter don't correspond to the layout of the .csv I mentioned above. I'm using the script from below on a test .csv that I wrote myself for now. Using the print part of the code to check the values of the variables.
i'm trying to make a (my first) maxscript wich allows me to import a .csv file as an animated timeline with some interaction from the user.
My .csv is built up per line as follows:
,,,,,,,,,
In this line the and all the following values are irrelevant to me. I've attached an example of the .csv file.
What I want to accomplish is that the MaxScript evaluates the second line in the .csv file(the first contains headers) and calculates the total duration of the Task.
I.e: #,Total_Planning,#,#,#,#,#,27-9-2012 5:00,2-10-2012 2:00,Construct
- So the total construction time would be 117 hours. This is easy for us to calculate, but is there a way to let MaxScript do this? Taking into account that the months do not always contain the same amount of days.
What I'm trying to avoid is to manipulate the .csv file myself.
I know excel can calculate the difference but can MaxScript start/call this function? (As I'm trying to avoid altering the .csv file myself)
This calculation is needed multiple times where the resulting values will be used as variables for different things, therefor I want to use MacScript. So far I haven't come further then defining the variables based on a filterstring.
I'm also curious about a way of coping with empty values in the .csv file.
Any help would be appreciated.
PS. I know the numbers for the string filter don't correspond to the layout of the .csv I mentioned above. I'm using the script from below on a test .csv that I wrote myself for now. Using the print part of the code to check the values of the variables.
(
fName = getOpenFileName caption:"Open file" types:"(*.csv)|*.csv|"
fS = undefined
if fName != undefined then
fS = openfile fName
if fS != undefined do
(
while (not eof(fS)) do
(
PR = readline fS;
PRF = filterstring PR ","
TN=PRF
TS=PRF
TE=PRF
TT=PRF
TSF = filterstring TS "- :"
DS=TSF as integer
MS=TSF as integer
YS=TSF as integer
HS=TSF
MiS=TSF
TEF = filterstring TE "- :"
DE=TEF as integer
ME=TEF as integer
YE=TEF as integer
HE=TEF
MiE=TEF
Print TN
Print TS
Print DS
Print MS
Print YS
Print HS
Print MiS
Print TE
Print DE
Print ME
Print YE
Print HE
Print MiE
Print TT
)--while
close fS
) --fS
)