Jump to content
  • Advertisement
Sign in to follow this  

MaxScript Help

This topic is 5399 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
	object_name = readvalue f;
	object_pos.x = readvalue f;
	object_pos.y = readvalue f;
	object_pos.z = readvalue f;
	object_rot.x = readvalue f;
	object_rot.y = readvalue f;
	object_rot.z = readvalue f;
	close f
But how do I actually make the copies now? [Edited by - Bouga on October 3, 2004 10:24:59 AM]

Share this post

Link to post
Share on other sites
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!


Share this post

Link to post
Share on other sites
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 :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!