Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / Need help writing a script that duplicates and aligns
  RSS 2.0 ATOM  

Need help writing a script that duplicates and aligns
Rate this thread
 
31853
 
Permlink of this thread  
avatar
  • Total Posts: 16
  • Joined: 30 January 2009 01:05 AM

Hi everyone, this is my first time posting here, I have been a daily reader for a while:)

I am new to programing and writing scripts for 3dsmax, and I have to say I’m a confused noob hehe…

I need some help writing a script (and yes I have been reading the excellent maxscript reference help files and tutorials), but I have to say I often get pretty confused with the way they explain things in the maxscript reference manual, as they often leave out small details that noobs like me really need to know/learn!

Anyways, here’s what I need my script to do:

Let’s say I have 250 billboard trees scattered across a terrain, and I now have to add a collision object (a rectangle box for example) to all those trees, perfectly aligned to every tree’s pivot center. Placing them 1 by 1 manually would take a long time.

So what I have in mind is this: I create my rectangle box name ColObject01, and select it. Then I run the script, and I need it to basically duplicate and instance ColObject01 as many times as there are trees, and then align each of those objects to the pivot center of every tree.

I could call my trees “Tree01, Tree02, Tree03 etc...” so that the script knows to align ColObject01, ColObject02, ColObject03 etc… to Tree01, 02, 03 and so on. Is this the right way to do it?

I’m not sure how to write a script like this, my knowledge at the moment is pretty basic, and I would really appreciate any help with this! Is there a similar script already out there that I could look at?

Thanks for your time!
Stephan



Replies: 0
avatar

I don’t think you need max script for this - you can just use the “clone and align tool” that is in the tools menu.  It lets you pick a list of object to align to and any offsets you might want.  If the naming is not what you like after you clone the objects you can use the Rename Objects under the Tools menu.



Replies: 0
avatar

RubenGarzaJr 08 July 2009 05:24 PM

I don’t think you need max script for this - you can just use the “clone and align tool” that is in the tools menu.  It lets you pick a list of object to align to and any offsets you might want.  If the naming is not what you like after you clone the objects you can use the Rename Objects under the Tools menu.

LOL I didn’t even think about that...I was so set on learning to write maxscripts that I didn’t even look for a way to do it already included in Max…

Out of curiosity now, I would like to still create that script for learning purposes. Any suggestions?

Thanks!



Replies: 0
avatar
  • Akram
  • Posted: 08 July 2009 07:30 PM

Firstly align the ColObject01 and its pivot to Tree01, then select all the trees except tree01 and

trees = selection as array
colobj = $ColObject01
for i in trees do
(
a = instance colobj
a.rotation = (i.rotation as eulerangles)
a.pos = i.pos
a.scale = i.scale
)



Akram
Technical Artist,
FxLabs Studios, India
http://akira-techart.blogspot.com/

Replies: 0
avatar

Akram 09 July 2009 02:30 AM

Firstly align the ColObject01 and its pivot to Tree01, then select all the trees except tree01 and

trees = selection as array
colobj = $ColObject01
for i in trees do
(
a = instance colobj
a.rotation = (i.rotation as eulerangles)
a.pos = i.pos
a.scale = i.scale
)

Thanks Akram!
Having 1 little problem with the rotation part...with the rotation line in, nothing happens (I don’t get any errors, just nothing happens). When I take the rotation line out, it works fine, except the new objects aren’t rotated of course.
I’m not sure what to try to fix it?

Thanks again for your help!



Replies: 0
avatar
  • Akram
  • Posted: 09 July 2009 06:30 PM

i have no idea why its not working for u, its working fine with the rotations for me.



Akram
Technical Artist,
FxLabs Studios, India
http://akira-techart.blogspot.com/

Replies: 0
avatar

Akram 10 July 2009 01:30 AM

i have no idea why its not working for u, its working fine with the rotations for me.

Yeah I figured I must be doing something wrong, I’ll figure it out :)

Thanks a lot for your help, I appreciate it!

Stephane



Replies: 0
avatar

it’s kind of depressing when you have set down the road of scripting some solution...maybe spent hours/ days on a script...only to find out there is some easy built in solution. :) It’s happened a couple times to me.



Gregory Mertens
mertens3d.com - recent 3d architectural rendering

My Max Bugs/Issues/ Requests

Replies: 0
avatar

gregory mertens 19 July 2009 08:28 PM

it’s kind of depressing when you have set down the road of scripting some solution...maybe spent hours/ days on a script...only to find out there is some easy built in solution. :) It’s happened a couple times to me.

In my situation I really don’t mind because I want to learn witting my own scripts anyways, so it’s a win/win situation for me either way. But yeah, if I was an experienced coder and did this, I would pull my hair out....lol



Replies: 0