Notifications
Clear all

[Closed] Need Help Import Data from File

Hi all, i have a incomprensible problem with my scrpt, im a beginner in MaxScript so i know only essential.

EXPLANATION:
Ok, my first test consist to import a data set from a binary file called .worldcollision (not text format) and create some array to build the scene.
I put in attachments the binary file, the converted binary file to text (ps: i know the structure of float, integer, short, bytes, ecc…) and the script.
In the second read function i append the point3 (x,y,z) into a big array called pivotBB, you can see this array in the text file: match with the first 3 float number of # Row no.0, # Row no.1 ecc…
So my intentio is to create an array pivotBB like this:
#([x1,y1,z1],[x2,y2,z2,],…,[xn,yn,zn])
so it’s very easy utilize this information for future function.

THE PROBLEM:
the first 3 points of # Row no.0 are “undefined”, WHY ??? because the sequence of other float, bytes, integer are correct, infact the other 3 point from # Row no.1,# Row no.2,ecc… are correct.

Can anyone explain the issue and help me to write code more efficient please ???

6 Replies

You’ve got this code:

 pt1 = [pt1.x,pt1.y,pt1.z]
 append pivotBB pt

but shouldnt it be:

append pivotBB pt1

?

or…
if you’re storing a point3 position, wouldnt this be better?:

pt1 = point3 p1.x pt1.y pt1.z
1 Reply
(@johnwhile)
Joined: 10 months ago

Posts: 0

Ok, i clean many error to script but now there are a incomprensible error ( in this time i have controlled the name punctiliously), the fist function have all variable to “undefined” ?!?!?!?
message error:

the file are the same, ( to run script open the file, clic on ReadHeader and ReadTable1…)
The open file function don’t return undefined so che file name “fin” are opened so why the read function give me anyway undefined ?? if i load file and function manualy by MaxScript listener is all ok

yes, it’s right and i know this way but the problem not change, in the max script listener if i write: pt1 it return “undefined”… now it’s possible ???

[QUOTE=dutch_delight]You’ve got this code:

 pt1 = [pt1.x,pt1.y,pt1.z]
      append pivotBB pt
     
 but shouldnt it be:
append pivotBB pt1
     
 OH, SHT !! thanks very much, i have wrote pt and not pt1.... this is an invisible problem :D:wip:!!

ehm, i simplified the program but it don’t work at the first time, only after reload and with maxscript listener:

What I think is happening:
The first time you run the program it crashes because the array is not defined. (the one you’re trying to append to) or the value is not defined.
The second time you run it, the array will be defined and so the append succeeds and it works fine.

Define the array at the top of your function like so:

 fn my_function = 
(
schar = #()  -- define schar as array
temp = readvalue infile
append schar temp
)

or you can do a test to see if the value is defined to prevent an error:

if temp != undefined then append schar temp

ok, thanks, but i resolved some day ago