[Closed] select and move polygons in MaxScript
I’m trying to make a script to offset the polygons of a mesh by a certain value in their local coordinate system on the z-axis. The mesh consists of a bunch of quads, separated from each other. I spent a few hours researching how to do this, but with no luck. There are a lot of methods about faces, but none about polygons. Manually it’s pretty simple: in the modify menu I click on the polygon selection, make sure Max is in the local coordinate system and simply move on the z-axis. The script should do just that, cycling through all the polygons of the object.
So how do I cycle through and select all the polygons of a mesh? Anybody got a clue?
Why loop through all of them you can simply select all faces in an edit poly by using
polyOp.setFaceSelection obj #{1..polyOp.getNumFaces obj}
And the same for edges/vertices
Or do you want to move them on the normal of the polygon which is a face!? ( http://en.wikipedia.org/wiki/Polygon :curious: )
Yes, I want to move a polygon a certain value along its normal. The polygon consists of two faces, so in fact it is a square. And the main object consists of a lot of these squares. Does this make any sense to you?
The only command I could find which pinpoints polygons is: meshop.getPolysUsingFace. What I want is probably possible with it, but it’s a pain in the ass this way and I don’t know where to start.
Well to loop that you could think of something like this
(
obj = $ --set object to current selection
total = #{1..meshop.getNumFaces obj} --set all faces in an bitarray
--using total as array.count becouse bitarray.count returns the total amount of bits not considering if they are set true or false
while (total as array).count > 0 do (
poly = meshop.getPolysUsingFace obj (total as array)[1] --get the faces per poly for the first face in the list
format "PolysUsingFace: % = %
" (total as array)[1] poly --do stuff with 'poly' (face index bitarray)
total -= poly --remove the poly just used from the bitarray
)
)
Alternatively you said you allready exploded all of them to elements so you could use getElementsUsingFace aswell.
Or another approach which might work could be using the modpanel select all, extrude by local, select inverse and delete mesh.
Thanks! This did the trick! The code is as follows:
total = #{1..meshop.getNumFaces object} --set all faces in an bitarray
--using total as array.count becouse bitarray.count returns the total amount of bits not considering if they are set true or false
while (total as array).count > 0 do
(
currentPolyIndex = (total as array)[1]
poly = meshop.getPolysUsingFace object currentPolyIndex --get the faces per poly for the first face in the list
--format "PolysUsingFace: % = %
" currentPolyIndexpoly --do stuff with 'poly' (face index bitarray)
total -= poly --remove the poly just used from the bitarray
local vertsToMove = meshop.getVertsUsedOnlyByFaces object poly -- get all verts of ply
local normal = in coordsys world getFaceNormal object currentPolyIndex -- get normal of plane
local offset = normal*(offset_distance as float)/100.0 -- user variable
in coordsys world meshop.moveVert object vertsToMove offset -- move the verts
)