face move script error

i made this script
this is script for moving face with 3 vertex
there is error
pls see attacef file

lastvetx = #()

curO = selection[1]

aFaces = (polyOp.getFaceSelection curO) as array

for selFaceBA in aFaces do
(

vertPos1 = polyop.getVertsUsingFace curO selFaceBA
vertPos = vertPos1 as array
vertPosArr = for v in vertPos1 collect (polyOp.getVert curO v).z
vertZmax = amax vertPosArr
topVertIdx = 0

for f = 1 to vertPos.count do
(

uuu = polyop.getvert curO vertPos[f]
vZpos = uuu.z

if vZpos == vertZmax do
(

topVertIdx = vertPos[f]
arraynum= f
)
)

for f = 1 to vertPos.count do
(

if ( (polyop.getvert curO vertPos[f]).z) < (polyop.getvert curO topVertIdx).z do append lastvetx (polyop.getvert curO vertPos[f])

)

ver_center = ((lastvetx[1]) + (lastvetx[2]))/2

nnnx = (polyop.getvert curO topVertIdx).x - ver_center.x
nnny = (polyop.getvert curO topVertIdx).y - ver_center.y

newver = [ver_center.x,ver_center.y,(polyop.getvert curO topVertIdx).z]

polyop.setVert curO vertPos[arraynum] newver

topVertIdx = 0

)

AttachmentSize
face_align.max228 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jahman's picture

.

what's the end purpose of the script that you're trying to make?
moving the topmost vertex in face to an average z value of the other two verts?

for f in polyop.getFaceSelection obj where ( polyop.getFaceDeg obj f ) == 3 do
(
    -- if face ideally horizontal
    if abs (dot (polyop.getFaceNormal obj f) z_axis) > 0.999 then
    (
         -- skip it ?
    )
    else
    (
         -- find the topmost vertex
         -- move it to an average value of the other two
         face_verts = (polyop.getFaceVerts obj f) as array
         vert_positions = for v in face_verts collect polyop.GetVert obj v
         index = 1
         max_z = vert_positions[ 1 ].z
         if vert_positions[ 2 ].z > max_z do
         (
            max_z = vert_positions[ 2 ].z
            index = 2
         )
         if vert_positions[ 3 ].z > max_z do
         (           
            index = 3
         )
         topmost = vert_positions[ index ]
         deleteItem vert_positions index
         topmost.z = ((vert_positions[1] + vert_positions[2]) / 2.0).z
         polyop.SetVert obj face_verts[ index ] topmost
    )
)

ps. It is a good idea to give script variables meaningful names.
'vert_position' instead of 'uuu' looks much better to anyone who will have to read your script (even you after a week won't remember what this variable is used for).
;)

dussla's picture

..

thank you jahman
very simple , you are genius always

this script purpose :
moving the topmost vertex in face to an average z value of the other two verts?

yes right

for roof style modification

thank you for good advice
i will use good name ~~

really thank you again~

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.