# MaxScript Help

## Recommended Posts

Bouga    322
Hi, can anybody help my out with max script? First of all, this is my first try at maxsript, and I have not had the time to look at some tutorials thoroughly, cos I need this script really fast, so dont flame me for not knowing the really simple things :) . Heres what I want to do: when I have a scene open in Max, run this script, that opens up a text file, reads in an object name, copies the object with that name to coordinates specified in the file. Example: if I have the following objects in my scene 1) Box1 2) Sphere2 3) SomethingElse and the text file contains: Box1 10 10 10 20 20 20 Box1 30 30 30 40 40 40 Sphere2 10 10 10 20 20 20 then the script should make two copies of the object Box1 at coords 10 10 10 and 30 30 30 with rotation angles 30 30 30 and 40 40 40 and one sphere at 10 10 10 with rotation angles 20 20 20 Heres what i have so far:
f = undefined

fname = getOpenFileName caption:"Find world object file" filename:"*.txt"

if fname != undefined then
f = openFile fname

object_name = "none"
object_pos = [0.0,0.0,0.0]
object_rot = [0.0,0.0,0.0]

if f != undefined then
(
while (not eof f) do
(

)
close f
)

But how do I actually make the copies now? [Edited by - Bouga on October 3, 2004 10:24:59 AM]

##### Share on other sites
Teknofreek    331
To access an object by name in Maxscript you need to use a dollar sign in front of the name. However, you can't use a string with the dollar sign followed by the name to copy an object, since the copy command will copy the string instead. However, you can use the execute command to turn the string into a node reference and use that to copy the object.

There's one other thing to note here. To be robust, you should place single quotes around the object name. This will handle the case where an object has spaces in it's name.

With the code you already have, here's what you would add to copy the object and set it's properties:

scene_object = execute ( "\$'" + object_name + "'" )
new_object = copy scene_object
new_object.pos = object_pos
new_object.rotation = ( eulerAngles object_rot.x object_rot.y object_rot.z )

Have fun!

-John

##### Share on other sites
Bouga    322
Thanks, this seems to be a much better solution compared to how I ended up doing it - selecting all abjects, looping through all selected objects and checking for name match, then deselecting the objects :)