[Closed] help MXS read external data
I meet a problem when I run a MXS to read data from a dat file
the data are as follow:
-15.7436,9.4353,-11.2804
96.011,-150.876,138.0289
-5.2103,-230.7725,122.3503
29.9328,-212.5843,9.2386
92.5178,-120.9492,-57.7814
-0.5455,1.8896,11.4197
-91.7734,124.0946,122.0455
-28.3564,213.9283,164.8463
4.4424,231.2096,84.569
-102.4511,155.1786,-55.0066
-15.7436,9.4353,-11.2804
and here is the script:
-- This Script will reset your scene, so save before running it.
resetMaxFile #noPrompt
s = sphere ()
spaz = s.pos.controller
-- Function Definition
fn AddKeysFromFile ctrl file=
(
local f = openFile file
t=0
while (not eof f) do
(
local x = addNewKey ctrl t
local a = [readValue f,readValue f,readValue f]
x.value = a
t += 10
)
close f
)
-- EVALUATE FUNCTION
AddKeysFromFile spaz "test.dat"
should tell us the problem you get
[color=Red]-- Error occurred in AddKeysFromFile()
-- Frame:
-- x: OK
-- file: "c:\3dsmax11\scripts\feh.txt"
-- ctrl: Controller:Position_XYZ
-- t: 0
-- f: <File:c:\3dsmax11\scripts\feh.txt>
-- a: [-15.7436,9.4353,-11.2804]
-- Unknown property: "value" in OK
[/color]
That should be a bit of a hint. The ‘OK’ value here is ‘x’. In your code, you use: “local x = addNewKey ctrl t”. So ‘addNewKey’ is returning an OK value when adding to your ‘ctrl’ (a Position_XYZ controller) instead of what you were expecting (a key value).
Now to figure out why, head to the help file:
If the controller is a compound controller (like a Position_XYZ controller), a value of OK is returned. A single key value cant be returned, as addNewKey creates a key in each of the sub-controllers.
Well, there you go
You’ll want to either…
A. Set the new keys on the subcontrollers of the Position_XYZ controller
B. Set the key on the Position_CYZ controller (as you do now), but when going to adjust the keys, get them -from- the subcontrollers first.
why are you readvalue 3 times?
local a = [readValue f,readValue f,readValue f] ??
Your basically going through the file, but reading each line as a component of an xyz.
Shouldnt it be:
while (not eof f) do
(
local x = addNewKey ctrl t
local line = filterString (readLine f) “,”
local val = [line[1]as float,line[2] as float,line[3] as float]
ctrl.value = val
t += 10
)
or line = execute (“[” + readLine f + “]”)
ctrl.value = line
something like this roughly
It might be much easier to just enable the with Animate On At Time t contexts and set the position of the object directly instead of setting explicit keys. This way, the type of controllers would not matter…
-- This Script will reset your scene, so save before running it.
resetMaxFile #noPrompt
s = sphere ()
-- Function Definition
fn AnimateObject spaz file=
(
local f = openFile file
t=0
while (not eof f) do
(
with animate on at time t spaz.pos = [readValue f,readValue f,readValue f]
t += 10
)
close f
)
-- EVALUATE FUNCTION
AnimateObject s "test.dat"
thanks guys, first I should tell that I am a newer, and I am sorry perhaps some things you said I can’t cacth it , and I tried the code you given, but sorry I got error again
uh , I just want to read the data from the file and to animate the object, and thanks again all of U
hi¡¡
i have a question about this script, how could I move and rotate the sphere?¿, I know how to move the sphere with this spript , but my question is about how to do both things, move an rotate.
thanks
[left]
[/left]
[left]for i in 1 to 10 do
[/left]
[left](
[/left]
[left]concourse[i].pos=pos0[i]
[/left]
[left]rotate concourse[i] x1[i] x_axis
[/left]
[left]rotate concourse[i] y1[i] y_axis
[/left]
[left]rotate concourse[i] z1[i] z_axis
[/left]
[left])
[/left]
[left][left]
[/left][/left]
[left][left]just an example, I think you can work out it with this code [/left][/left]