[Closed] Importing excel data for noobs
There’s been some posts asking how to do this so I thought I’d add some code as I improved it. The idea is to take an excel file and use it to bring in boxes w/ geometry pos etc. The end result is to have everything updated w/ time. I admit I’m a noob myself, just wanted to help out any other noobs. Most of it comes from what other people helped me w/ but I thought I’d try to help any others like myself with some dumbed down explanations.
I’ve added the text file NameSizePos.txt. Just change the extension to .csv.
First an excel file (I think) needs to be saved as .csv
For purposes of this I’ve got it saved on the c drive.
(
f = openfile “c:\NameSizePos.csv”–I’ve tried to change this to different folders but the program couldn’t find them so all I do is leave it on the c drive (any help would be appreciated)
if (f != undefined) then–checks to see if your file exists
(
skiptonextline f–The file has headers to identify the columns. This tells the script to skip them and start on the next line where the data is
while not eof f do–Starts a loop that will go until the end of the file. “eof f” tells it end of file and f is the file name. So the loop will run so long as it hasn’t hit the end of the file.
(
BoxName = readdelimitedstring f “,”–reads the first string up to a “,” In this case it’s the name of the box being created.
Xsize = readValue f–reads the x size
Ysize = readValue f–ditto for y
Zsize = readValue f–ditto for z
Xpos = readValue f–reads the x position
Ypos = readValue f–ditto for y
Zpos = readValue f–ditto for z
Box length:Xsize width:Ysize height:Zsize mapcoords:on pos:[Xpos,Ypos,Zpos] isSelected:on name:BoxName–Makes a box w/ the name sizes and positions it read for the .csv file line it’s currently on
)–Don’t worry about adding “skiptonextline” telling it to go to the next line. The while loop does that automatically
close f–closes the file
)
else–action if there was an error opening the file
(
messageBox “Open Failed” title:“Error!”–puts a message on the screen if there was an error opening the .csv file.
)
)
I initially had some weirdness w/ the file and then resaved it and it worked fine. Anywho it’s consistently okay now so I hope anyone trying this won’t have any problems.