PDA

View Full Version : Copying and relocating in script?


NewETown
01-14-2008, 08:19 PM
So I'm trying to copy an object (compound object) in my scene to make a tower. I want to be able to run a script that will tell Max (9) to copy the object and move it up on Z, or adjust on any axis, a specific number of units. I've sat here for about an hour going through my texts and searching and can't seem to find anything. Something that bothered me was when I enable the macro recorder nothing happens. I've only been using Max for about a week, so I'm a little bit new to the program. Any suggestions?

NewETown
01-15-2008, 02:32 AM
Bump, does anyone have any suggestions? Ideally I'd like to let someone come in and imput the number of segments they want then have the script form the tower out of the compound objects that I've already created.

Jon-Huhn
01-15-2008, 02:35 AM
So are you just looking for the script to take one object and make copies of it X number of times X units apart on the Z axis?

NewETown
01-15-2008, 08:42 AM
Yes basically. I can't seem to figure out what command max script is looking for to copy the selected object. It really doesn't even have to be the selected object, just any object. I tried modifying a few scripts I already had (basically tutorial scripts) that involved making copies of a certain object but wasn't able to get them to work.

For instance, I have no problem making a sphere array script (from the Max 9 bible), but I don't know how to change it specifically to do what I want it to do. When I change my sphere array script I get error messages, which is most likely me messing up something, but I've checked over it a few times and really don't know where else to look.

Gravey
01-15-2008, 09:27 AM
if all you want to do is copy and move an object, use the built in array tool found under the Tools Menu - Array... and press the preview button if you want to see the changes in the viewport as you make them
For instance, I have no problem making a sphere array script (from the Max 9 bible), but I don't know how to change it specifically to do what I want it to do.If the array tool does not do what you need then you need to give some more info as to what specifically it is you want to do so we can help

NewETown
01-15-2008, 07:38 PM
The array tool is very similar to what I'm looking for. I'm sorry my details are vague, it's sort of difficult for me to explain what I need to do.

I'll use an example, say I wanted to build a very low poly tower (or skyscraper, some sort of segmented vertical structure), but I wanted someone else to be able to come in and define how high they wanted it to be. Basically I'm going to somehow use this script to allow people to define the height of a tower (outside of Max) and run the script which will produce an image for them to see. I don't know how much of what I want to accomplish can be automated but I hope that I can at least make some sort of cool menu that people will find easy to use and easy to understand.

For my menu I was thinking of having two spinners (most likely using integers), one for height and one for the number of segments. It is very important that the segments stay connected. It might be easier to just define a height that scales to the already completed tower (so that it stays in proportion with a real tower) but I'd like to get as customized as possible. Then I'll have a selection of different types of towers (using radiobuttons) and ultimately full Lat/Long co-ords that people can input. After the information is recieved I'd like to be able to give people an automatically generated picture of the scene they just told the script to do so they can visualize the site that they want their tower placed at.

Sorry to be so long winded but I'm trying to give as much detail as possible. Thanks in advanced for all of the help!

NewETown
01-15-2008, 08:31 PM
Ok I finally got the object to be copied on the Z axis, which was just a matter of me paying attention to the script and not being a complete noob. Here is what I have so far:


utility objCopy "Object copy"

(

spinner objCount "Object count:" range:[1,100,4] type:#integer

spinner radius "Radius:" range:[1,1000,20] -- useless at the moment

button go "Go!"

on go pressed do

(

a = selection[1]

if a != undefined do

(

c = objCount.value

r = radius.value -- another useless thing
for i = 1 to c do

(

h2 = h * i

someObj = copy a

someObj.position.z = someObj.position.z + h2 + i

)

)

)

)



So now I need to adjust the distance at which the objects are copied from the first one. I don't know how to make the object copy a certain number of units above it. Also, this is working for primitives but will it work for compound objects and editable poly's?

NewETown
01-15-2008, 09:39 PM
Aha! I got it (with some massive help from a co-worker) and here's what it looks like.


utility objCopy "Object copy"

(

spinner objCount "Object count:" range:[1,100,4] type:#integer

button go "Go!"

on go pressed do

(

a = selection[1]

if a != undefined do

(

c = objCount.value

h = getLocalHeight a

for i = 1 to c do

(

h2 = h * i

someObj = copy a

someObj.position.z = someObj.position.z + h2 )

)

)

)



fn getLocalHeight node = (

local msh = snapshotAsMesh node

local invTransform = inverse node.transform

local pt = (getVert msh 1) * invTransform

local minHeight = pt.z

local maxHeight = pt.z

for i in 2 to msh.numVerts do (

local vert = (getVert msh i) * invTransform

if vert.z > maxHeight do

maxHeight = vert.z

if vert.z < minHeight do

minHeight = vert.z

)

delete msh

return (maxHeight - minHeight)

)

CGTalk Moderation
01-15-2008, 09:39 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.