help MXS read external data

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  03 March 2009
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:

and here is the script:
HTML Code:
-- 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"
  03 March 2009
should tell us the problem you get

-- 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

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:
Quote: If the controller is a compound controller (like a Position_XYZ controller), a value of OK is returned. A single key value can’t 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.
  03 March 2009
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
Disclaimer: My opinions are not those of my employer.

  03 March 2009
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
	 while (not eof f) do
		with animate on at time t spaz.pos = [readValue f,readValue f,readValue f]
		 t += 10
close f
AnimateObject s "test.dat"

Last edited by Bobo : 03 March 2009 at 06:45 PM.
  03 March 2009
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
  03 March 2009
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.

  03 March 2009
for i in 1 to 10 do
rotate concourse[i] x1[i] x_axis
rotate concourse[i] y1[i] y_axis
rotate concourse[i] z1[i] z_axis
just an example, I think you can work out it with this code
  03 March 2009
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 06:28 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.