PDA

View Full Version : "How to write an Align to polygon normal function"


JepMasterAce
02-19-2006, 10:44 PM
Hi, I'm new to maxscript but not new to max. I just started to learn maxscript yesterday. I was wondering if it's possible to align objects a polygon normal via maxscript. I tried using macro recorder but it doesn't give me any code when using the align to. The script i'm trying to write a script that generates an object the same length and with of a selected polygon. I may sound like i'm jumping the gun but I'm used to coding in C++. Any help would be greatfully appreciated.

f97ao
02-20-2006, 06:03 PM
Hi, I'm new to maxscript but not new to max. I just started to learn maxscript yesterday. I was wondering if it's possible to align objects a polygon normal via maxscript. I tried using macro recorder but it doesn't give me any code when using the align to. The script i'm trying to write a script that generates an object the same length and with of a selected polygon. I may sound like i'm jumping the gun but I'm used to coding in C++. Any help would be greatfully appreciated.

Hi there Jep, and welcome to MaxScript. :)

If you are used to c++, maxScript should be simple. Look in the help for editable_poly and the polyOp commands. I don't remember all of them and don't have the help here so I just write it in pseudo code (and a few lines of maxScript from memory)

What you want to is first:
- Check that an object is selected. if IsValid($) then (...)
- get the Face selection. theSelection=$.baseObject.GetSelection #Face
- Figure out what you want to do if the user doesnt' have a face selection (perhaps vertex instead), and also if they have many faces selected. if theSelection.count>1 'figure out what to do.
- Get the face normal.
- Move the object to the center point of the face selection.
- rotate the object to the face normal

Hope that helps anything.
/Andreas

joconnell
02-21-2006, 01:52 PM
Heya!

Here's the functions for position and normal:

the_pos = polyop.getfacecenter $name_of_selected_object number_of_poly_you_want
the_dir = polyop.getfacenormal $name_of_selected_object number_of_poly_you_want

so something like:

the_pos = polyop.getfacecenter $box01 10
the_dir = polyop.getfacenormal $box01 10

will get the tenth poly of object called box01

then you can use

myobj.pos = the_pos
myobj.dir = the_dir

Hope this points you in the right direction.

JepMasterAce
02-25-2006, 06:27 PM
Ahh! Thanks for the replys! It was really helpful!

CGTalk Moderation
02-25-2006, 06:27 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.