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 CLOSED
 
Thread Tools Search this Thread 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:
-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:
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
	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"
__________________
Bobo

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
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
 
  03 March 2009
 
for i in 1 to 10 do
(
concourse[i].pos=pos0[i]
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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 03:17 AM.


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