PDA

View Full Version : what's wrong?


flyingaway
04-01-2009, 12:49 PM
body=box width:32 length:32.5 height:3 pos:[0,0,49.3] name:"body"
for i =1 to 22 do
(
copy body pos:[32*i,0,49.3] name:("body+"+i as string)
copy body pos:[-32*i,0,49.3] name:("body-"+i as string)
)
s=box width:300 length:32.5 height:3 pos:[870,0,49.3] name:"s"
n=box width:350 length:32.5 height:3 pos:[-895,0,49.3] name:"n"
group $body* name:"Bbody"
bigones = for obj in $body* -- you can sequence pathnames!
where obj.height > 0.030 collect obj
with animate on
for i=1 to bigones.count do
(

t=0
(
bigones[i].pos+=point3 (random -0.3 0.3) (random -0.3 0.3) (random -0.3 0.3)
t+=5
)
)
seems simple , but I really dont know where the mistake is

SyncViewS
04-01-2009, 01:04 PM
Hi,
I don't really know what you're trying to do, so I'll give it just a shoot.


body = box width:32 length:32.5 height:3 pos:[0,0,49.3] name:"body"

for i = 1 to 22 do
(
copy body pos:[32 * i, 0, 49.3] name:("body+" + (i as String))
copy body pos:[-32 * i, 0, 49.3] name:("body-" + (i as String))
)

s = box width:300 length:32.5 height:3 pos:[870,0,49.3] name:"s"
n = box width:350 length:32.5 height:3 pos:[-895,0,49.3] name:"n"

group $body* name:"Bbody"

bigones = for obj in $body* where (obj.height > 0.030) collect obj

with animate on
(
for t = 0 to 100 by 5 do
(
at time t
for i = 1 to bigones.count do
(
bigones[i].pos += point3 (random -0.3 0.3) (random -0.3 0.3) (random -0.3 0.3)
)
)
)

- Enrico

flyingaway
04-02-2009, 01:35 AM
thanks , yeah , I just want do this ,but this is a test
the next step , I want to read data from a file and animate those boxes
that maybe a little difference ,but the theory is same I think
there is a long way for me to travel in the maxscript :sad:

flyingaway
04-03-2009, 03:00 AM
with animate on
(
f=getopenfilename types:"data(*.dat)|*.dat|all|*.*"
thefile=openfile f
while(not eof thefile) do
(
for t = 0 to 100 by 5 do
(
at time t
for i = 1 to bigones.count do
(
bigones[i].pos += point3 (readvalue thefile)(readvalue thefile) (readvalue thefile)
)
)
)
)
:sad: uh , what is wrong with the code , get erro
-- Unable to convert: "0.00780191 0.0239268 -0.0230994" to type: Float

ZeBoxx2
04-03-2009, 04:30 AM
bigones[i].pos += point3 (readvalue thefile)(readvalue thefile) (readvalue thefile)
:sad: uh , what is wrong with the code , get erro
-- Unable to convert: "0.00780191 0.0239268 -0.0230994" to type: Float

You're trying to cast the read value to a point3 as if 'point3' were a function taking 3 arguments :) try:

bigones[i].pos += [readvalue thefile, readvalue thefile, readvalue thefile]

Edit: Though you may wish to use readLine, and then parse the read line from that - that's noticeably faster especially if you have a lot of lines with point3 coordinates on them.

thatoneguy
04-03-2009, 04:54 PM
Actually you can cast a point 3 by just taking in 3 variables.

try running this in your listener:

bob = box()
bob.pos += (point3 3 3 3)

I suspect this is what's ACTUALLY happening though:

bob = box()
bob.pos += (point3 "3" "3" "3")


but this should work:

bob = box()
bob.pos += (point3 (("3") as float) (("3") as float) (("3") as float))

ZeBoxx2
04-03-2009, 05:18 PM
oie - I should stop posting at 5:30am :applause:

Edit: or.. continue posting at 5:30am - as 'readValue' casts the read value to a string implicitly (though I'll be darned if I knew about the 'point3 x y z' thing):

test = stringStream "5 10 20"
StringStream:"5 10 20"
point3 (readvalue test) (readvalue test) (readvalue test)
[5,10,20]

So.. I guess the actual problem is that his 'readValue' ends up reading all 3 values, instead of just one? o_O

flyingaway
04-04-2009, 01:44 AM
function writeout = (
a=-0.1
b=0.1
extfile = createfile "f:/randomdata.dat"
for i= 1 to 44 do (
format "set %\n" i to:extfile
for k=1 to 500 do (
format "% % %\n" (random a b) (random a b) (random a b) to:extfile
)
format "end set %\n" i to:extfile
format "\n" i to:extfile
)
close extfile
)
writeout()

I used the up code(losbellos wrote it ) to create data at first
but get erro
so I changed the code a little as follow:
--format "set %\n" i to:extfile
--format "end set %\n" i to:extfile
--format "\n" i to:extfile
but still get erro
-- Runtime error: Read past end of file
here I give out the full code I wrote ,maybe that will help to figure out why I got the erro
body = box width:32 length:32.5 height:3 pos:[0,0,49.3] name:"body"
for i = 1 to 22 do
(
copy body pos:[32 * i, 0, 49.3] name:("body+" + (i as String))
copy body pos:[-32 * i, 0, 49.3] name:("body-" + (i as String))
)
s = box width:300 length:32.5 height:3 pos:[870,0,49.3] name:"s"
n = box width:350 length:32.5 height:3 pos:[-895,0,49.3] name:"n"
group $body* name:"Bbody"
bigones = for obj in $body* where (obj.height > 0.030) collect obj
with animate on
(
f=getopenfilename types:"data(*.dat)|*.dat|all|*.*"
thefile=openfile f
while(not eof thefile) do
(
for t = 0 to 100 by 5 do
(
at time t
for i = 1 to bigones.count do
(
bigones[i].pos += point3 (readvalue thefile)(readvalue thefile) (readvalue thefile)
)
)
)
)

ZeBoxx2
04-04-2009, 07:30 AM
well the first error I get with your code 'as is', is:

-- Compile error: Illegal input in readValue
-- In line: set 1


Basically that's MaxScript telling me that I can't use readValue for that line as it doesn't know how to convert that to any meaningful value.

So I'll have to use readLine instead and make sure I'm not parsing those 'set N' and 'end set N' bits as position values; store them in some other variable instead as I guess you'll need them for something later.

Once I've done that, I've got those point 3 values as a single string per 3 and can convert those myself.

Now as to the 'read past end of file'.. you've got 3 loops going on... one that says MaxScript should continue until -in that loop- the end of the file has been reached, another that loops over time and another that loops over the the 'big objects'. That outer 'continue until end of file reached' one is the problem.
Let's say that in that outer 'while (not eof theFile)', we've reached 1 line from the end of the file. Then the inner loops run which read the line (21 * bigObjects.count) times.. many more than the number of lines actually remaining in the file.
So that loop can go and instead a check for eof can be added where you actually read the line, perhaps seeking to 0 so that it can start from the top of the file again in the unlikely event that it does, in fact, reach the end of the file.

Ends up looking something like this:

with animate on (
f=getopenfilename types:"data(*.dat)|*.dat|all|*.*"
thefile=openfile f

for t = 0 to 100 by 5 do (
at time t
for i = 1 to bigones.count do (
local theLine = readLine thefile
if (eof thefile) do ( seek thefile 0 )
local mySet
if (matchPattern theLine pattern:"set *") then (
mySet = (filterString theLine " ")[2] as integer
)
else if (matchPattern theLine pattern:"end set *") then ( )
else if (theLine == "") then ( )
else (
local myPoint3Array = filterString theLine " "
local myPoint3 = point3 (myPoint3Array[1] as float) (myPoint3Array[2] as float) (myPoint3Array[3] as float)
bigones[i].pos += myPoint3
)
)
)
)

I'm not sure the result is actually what you're looking for, though, but that's of later concern :)

flyingaway
04-04-2009, 02:23 PM
thanks .
well , it is good.
the first step was completed
but there is still a long way to travel

CGTalk Moderation
04-04-2009, 02:23 PM
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.