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® / 3ds Max through 2008 / Need help writing what should be a simple script
  RSS 2.0 ATOM  

Need help writing what should be a simple script
Rate this thread
 
8312
 
Permlink of this thread  
avatar
  • David V
  • Posted: 12 February 2008 04:30 PM
  • Total Posts: 3
  • Joined: 12 February 2008 03:47 AM

Although I’ve been using Max since 3D Studio Dos v.2, I have never approached the power of scripts. I’d like to write a script that would do these commands…
1. select all (select all objects in the scene)
2. Affect Pivot Only > Align to World
3. Reference coordinate system = World
4. Rotate type in dialog open
5. X=90 Y=0 Z=180

Using the MAXScript Listener I’ve only gotten this far…
actionMan.executeAction 0 “40021” —Selection: Select All
max hierarchy mode
align to world [script doesn’t recognize this data]
toolMode.coordsys #world
max rotate
max tti
x=90 y=0 z=180 [script doesn’t recognize this data]

any help on this would be greatly appreciated.
Thanks,
Dave



Replies: 0
avatar

Hola!
First off, don;t use the listener to grab commands, here lies only fear and despair.

are you familiar with programming at all?

The best way to do this is to use something called a loop, basically an action that is performed on each object.

for example, lets say we want to print the name of each of our selected objects to the listener. (open the listener first! :)

type in the following;

clearlistener()
for i in 1 to selection.count do
(
print selection.name
)

lets step through this;

clearlistener() - this will clear the output of the listener for you, handy.
selection is what you have selected, its stored in an array which is a list of objects. the first line;
for i in 1 to selection.count do
this is telling max that it needs to go through each object in the selection array. i is the index of the object. everything in the next set of brackets is going to be run on each object.

here is what we have in those brackets;
print selection.name

this tells max to print the objects name, selection is the array and the i is the index position…

so thats basically a for loop.

now lets get to the meat of what you want to do.

here is a script that takes all of your selected objects and aligns the pivots to the world;
clearlistener()
for i in 1 to selection.count do
(
worldalignpivot selection
)

just like above, i am looping through all of the objects i have selected and running the command “WorldAlignPivot” on that object, which aligns the pivot to the world.

I encourage you to use maxscript help to look up some of these commands.

anyway, thats just a start, i could write you the script that you want but i would rather teach you to fish if you get my drift :)

good luck…



Replies: 0
avatar
  • focomoso
  • Posted: 14 February 2008 12:32 AM

Aaron, a couple of points. First, while:

for i in 1 to 10 do

works, better syntax would be

for 1 to 10 do

to avoid confusion with:

for obj in selection do

which is exactly the mistake you make in your last snip.

for i in 1 to selection.count do
(
    
worldalignpivot selection
)

takes the entire selection and calls worldalignpivot() on it as many times as there are objects in the selection (so if you have 10 objects selected, each one’s pivot is aligned to the world 10 times).

All you need to do is call

worldalignpivot selection

once, outside of a loop and everything in the selection will be aligned (it’s a mapped function).

But, if you want to do more complex stuff with each object in the selection, you’d do:

for obj in selection do (
    
worldalignpivot obj
    
-- other stuff to obj
)

So david, the way to select all the objects in the scene is to use:

select objects

but you don’t really need that, instead, you can run you script on ‘objects’ which will work on everything in the scene, so you get:

worldalignpivot objects

It’s a start, at least.



--
James Kelly
fo co mo so

Replies: 0
avatar

You are right, that was a bad use of selections, (oops I actually never use that method, i usually gather the selection and build a new array to work on using functions to sort by object type/etc but thats over the head of a beginner...)

Its a shame that the listener is still next to useless, and only seems to confuse people that are starting out (the stupid “actionMan” stuff) i have complained to larry several times on that one :)

I am new to the board, but have been using max since it was dos, and writing tools/scripting for as long as it existed (max2 ftw:)



Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14435
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

This thread would probably be better suited to the MaxScript forum. Ask one of the [FA]s to move it for you.



Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.

Replies: 0