View Full Version : Box creator
Hello!
I would like maxscript to read a text file
and generate a box at the (x data from file,ydata from file) coordinates width(0.9) lengt(0.9) hight(data from file) with the name (data from file)
the content of the file look like this:
5452,Gubba dagis,33679,575,508,270,K55
the value "Gubba dagis" is the name
the value "575" is x coordinate
the value "508" is y coordinate
the value "270" is is the hight
Can this by done?
And how does the code look?
Or Were can i find this script/info on how to do this script?
Please i need help
|
|
Dmaxer
11-26-2008, 11:53 AM
yeah this can be done look ,info is in the help that comes with max . I used a text file in my fftmax script to animate a set of boxes you could have a look at that script ,it should give you a idea of where to start :).
heres a link to my script
http://www.dmax-scripts.co.uk/Index_files/Scripts_files/FFT_files/FFT.htm
DaveWortley
11-26-2008, 02:20 PM
Wow, Danny I could have really done with your Piano MIDI maxscript a few years ago when I did this for my university project, had to animate it all by hand!
http://uk.youtube.com/watch?v=6YnqC8FYiMI
Kramsurfer
11-26-2008, 08:53 PM
dave: Wow... How many hours on the piano animation? Just a little bit of detail... nice.
Iro:
I don't have max to test this, but here's some non error trapped starter code..
FS = openFile <Data filename>
do(
-- reads in from file
tnLine = readLine FS
-- divides line into an array by the ,'s
tnData = filterString tnLine ","
-- create Box
newBox = Box name:tnData[2] pos:[tnData[5],tnData[4],0] height:tnData[6]
-- do till end of file
)while( not EOF FS)
You can add more box attributes after the box is made like this
newBox.wirecolor = ( color 120 120 120 )
checkout "Node Common Properties" and "Box" in the MSX help file
Good luck!
DaveWortley
11-26-2008, 10:31 PM
dave: Wow... How many hours on the piano animation? Just a little bit of detail... nice.
My First year, first semester coursework at uni, 20 credits worth for the animation 20creds for R&D portfolio, used some scripting to help me animate, just had to select the notes and click an option for how long it'd get played for and it'd automatically put the keyframes in for rotation and everything else was wire-parametered. Still wish I could have just chucked in a MIDI. Probs spent about 5 weeks on it, back in 3dsmax 5 with Scanline, not bad for my first propper animation? eh ;)
For first animation Dave that was fantastic.
FS = openFile "C:\\medlemmar2.txt"
do(
-- reads in from file
tnLine = readLine FS
-- divides line into an array by the ,'s
tnData = filterString tnLine ","
-- create Box
function newbox
newBox = Box name:tnData[2] pos:[tnData[4],tnData[5],0] length:0.9 height:0.9 height:tnData[6]
-- do till end of file
)while( not EOF FS)
I can't get it to work
What am i doing wrong??
i am not good at this :(
sorry!
Kramsurfer
12-01-2008, 04:14 PM
Are there data lines in the txt file that do not look like the sample provided? if so it will error on those? What does the error say?
the "function newbox" line will create an error...
Dmaxer
12-01-2008, 10:03 PM
great animation , hope you got your script sorted ?
All the lines are alike
5452,Gubba dagis,33679,575,508,270,K55
id name id2 x y size id3
The code:
FS = openFile "C:\medlemmar2.txt"
do(
tnLine = readLine FS
tnData = filterString tnLine ","
newBox = Box name:tnData[2] pos:[tnData[4],tnData[5],0] length:0.9 height:0.9 height:tnData[6]
)while( not EOF FS)
the error:
<File:C:\medlemmar2.txt>
-- Error occurred in anonymous codeblock
-- Frame:
-- Unable to convert: "575" to type: Float
OK
Can sombody tellme whats wrong???
labbejason
12-05-2008, 08:43 PM
Right now, I'm pretty sure you're trying to assign a string to a float value. Therefor, make sure you convert it to float before assigning it to the object's position.
For example, you can either do:
pos:[(execute tnData[4]), (execute tnData[5]), 0]
or
pos:[(tnData[4] as float), (tnData[5] as float),0]
DaveWortley
12-06-2008, 03:18 PM
For first animation Dave that was fantastic.
great animation , hope you got your script sorted ?
Thanks guys. I had been messing around with max and 3d programs for a couple of years before Uni, but nothing serious.
I remember my uni lecturer thinking I was crazy to attempt the whole piano and insisted I concentrated my time on just doing one key, long time ago... 4 or 5 years hehe, how things have changed!
P.S. Sorry for post-hijacking, will be doing something similar with particles soon so is very interesting.
The code:
FS = openFile "C:\medlemmar2.txt"
do(
tnLine = readLine FS
tnData = filterString tnLine ","
newBox = Box name:tnData[2] pos:[tnData[4],tnData[5],0] length:0.9 height:0.9 height:tnData[6]
)while( not EOF FS)
the error:
<File:C:\medlemmar2.txt>
-- Error occurred in anonymous codeblock
-- Frame:
-- Unable to convert: "575" to type: Float
OK
Can sombody tellme whats wrong???
Use readValue not readLine - read line reads each line as a string - you would therefore have to convert the string into a float.
while not Eof infile do
(
array = readValue infile
b = box()
b.length = array[1] etc etc..
)
Right now, I'm pretty sure you're trying to assign a string to a float value. Therefor, make sure you convert it to float before assigning it to the object's position.
For example, you can either do:
pos:[(execute tnData[4]), (execute tnData[5]), 0]
or
pos:[(tnData[4] as float), (tnData[5] as float),0]
Using execute in a script like this would be pretty bad, good for having to rebuild ui or a system that can only be evaluted by execute, but not reading a file.
It WORKS!!! :)
the solution:
FS = openFile "C:\medlemmar.txt"
do(
tnLine = readLine FS
tnData = filterString tnLine ","
x=tndata[4]
x=x as float
y=tndata[5]
y=y as float
h=tndata[6]
h=h as float
h=h/100
Box name:tnData[2] isSelected:on
move $ [x,y,0]
$.length =0.9
$.width =0.9
$.height = h
)while( not EOF FS)
Thank you all for your help
I am so happy :)
It WORKS!!! :)
Thank you all for your help
I am so happy :)
My Pleasure :)
CGTalk Moderation
12-11-2008, 03:30 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.