PDA

View Full Version : data base reading


nebille
11-02-2005, 03:35 PM
Hi all

I wondered if anyone knew how to get information from an excel spreadsheet into max

regards

Nebille

j-man
11-02-2005, 04:59 PM
Hi Nebille,

Firstly you would export your excelsheet as a CSV text file, and then write a simple maxscript importer. There are plenty of these on www.scriptspot.com (http://www.scriptspot.com/)

It might help if you could provide a sample piece of data, or tell us a little more about it. Look on scriptspot and see how they use commands like:

fileopen
redelimiteredstring
readline
skiptostring

plus plenty of others. Also, read in the MXS help under filestream values.




nebille
11-02-2005, 05:16 PM
Hi J


I have lots of coordinates ie X Y Z in an excel spread sheet and want to be able to extract this info to place objects in the scene according to the cords in excel. I geuss i just need to know how to get the info from each cell in excel

regards

Nebille

stuh505
11-02-2005, 07:42 PM
I geuss i just need to know how to get the info from each cell in excel


jman just told you. instead of saving as xls, save as csv...you can continue to edit your data using excel in this form. you can also very easily read the data by parsing with max script...if you want the the data at [row=2, col=3] then get the second line after the 3rd comma

nebille
11-03-2005, 08:43 AM
Cheers guys, i will research this more to get a better understanding of what is happening,

regards

Nebille

nebille
11-03-2005, 11:42 AM
Guys i have just written the script, thanks for the direction. I have a little problem that i hope you can help me with. At the moment i have to count how many lines are in the outputed .csv file and enter the number manually for the loop to get all the info. Ideally i would like to be able to say something like file.lines.count to find out how many lines are in the file.

Is this possible

regards

Nebille

allonym
11-03-2005, 11:56 AM
do something like:

while not eof myfile do
(
...
)


<allonym>

nebille
11-03-2005, 12:36 PM
works a treat, thanks for all the help people it makes forums like this a pleasure to use

regards

nebille

j-man
11-03-2005, 03:26 PM
Hi nebille,

I tihnk you're going down the wrong path.

Try something like:


f=openfile "mayfile.txt"
while not eof f do
(
x=readelimitedstring f ","
print x
)
close f

nebille
11-04-2005, 09:28 AM
Thanks J

I will investigate your code today. All things are working fine within the script that i have written. Is there any reason why i should use the readlimited method over the eof loop.

regards

Nebille

j-man
11-04-2005, 02:10 PM
Wow that post came in pretty late didn't it!


Nebille you would use any of these methods in the filestream section of the help depending on how your source data is formatted. The whole point of a CSV document is that each piece of data is seperated by a particular string , a comma in this case so you can use readdelimtitedstring. If you can read a line at a time then use readline instead.
Have a good read in the help so you have a good understanding of how the different commands work.
If you're reading x, y, z, data you could and your data looks like:

0, 0, 0,
0, 0, 0,

you could:

pos=#()
f=openfile "myfile.txt"
while not eof f do
(
x=(readelimitedstring f ",")
y=(readelimitedstring f ",")
z=(readelimitedstring f ",")
append pos [x,y,z]
)
close f


[0,0,0]
[0,0,0]

you could:

pos=#()
f=openfile "myfile.txt"
while not eof f do
(
append pos (readline f)
)
close f


Josh.

nebille
11-04-2005, 02:21 PM
thanks j

i was using the readline method

cheers for the codes , its always interesting to see how other people code.

regards

nebille

CarlosA
11-06-2005, 01:10 PM
i personaly also like the filterString command
if you say somethin like
filterString "xInfo,yInfo,zInfo" ","
it will re turn
#("xInfo","yInfo","zInfo")
then you can just treat it like an array.
not that any of the other ways are bad, i just realy like filterstring.

CGTalk Moderation
11-06-2005, 01:10 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.