distrubte vertices evenly on an edgeloop


#10

Well, I’ve been meaning to make this script. So here you go.

Run on selected mesh components
redistributeVertex(ch=False)


def redistributeVertex(ch=False):
    ''' redistribute vertex based on a uniform curve '''
    selection = cmds.ls(sl=True, fl=True)
    orgSel = selection
    verts = cmds.polyListComponentConversion(selection,
        fromFace=True,fromEdge=True,fromVertex=True,
        toVertex=True, internal=False)
    verts = cmds.ls(verts, fl=True)
    # convert to edge so we can use polyToCurve to fix vert order issues
    edges = cmds.polyListComponentConversion(selection,
        fromFace=True,fromEdge=True,fromVertex=True,
        toEdge=True, internal=True)

    vertData = {}
    positions = []
    for ii, vert in enumerate(verts):
        pos = cmds.xform(vert, q=True, ws=True, t=True)
        positions.append(pos)
        data = {'vertex':vert,'vertexPos':pos,'cv':None,'cvPos':None}
        vertData[ii] = data

    #create Curve
    cmds.select(edges, r=True)
    curve = cmds.polyToCurve( form=2, degree=1)[0]

    #find the matching cv
    cvList = []
    cvs = cmds.getAttr('{}.cv[li]'.format(curve))
[/li]    for i in range(len(cvs)):
        curveCV = '{}.cv[{}]'.format(curve,i)
        cvList.append(curveCV)
        cvPos = cmds.xform(curveCV, q=True, ws=True, t=True)
        for vert, data in vertData.items():
            vertex = vertData[vert]['vertex']
            pos = cmds.xform(vertex, q=True, ws=True, t=True)
            roundCvPos = [round(x, 3) for x in cvPos]
            roundPos = [round(x, 3) for x in pos]
            if roundCvPos == roundPos:
                vertData[vert]['cv'] = curveCV
                continue

    cmds.rebuildCurve(
            curve, ch=1, rpo=1, rt=0, end=1, kr=0, kcp=0, kep=1, kt=0, s=0, d=1, tol=0.01)
    #set New vertex postion
    for vert, data in vertData.items():
        vertex = vertData[vert]['vertex']
        curveCV = vertData[vert]['cv']
        if curveCV:
            cvPos = cmds.xform(curveCV, q=True, ws=True, t=True)
            vertData[vert]['cvPos'] = cvPos
            cmds.xform(vertex, ws=True, t=cvPos)
        else:
            print "No matchign Cv found for vertex",  vertex
    if not ch:
        cmds.delete(curve)
    if orgSel:
        cmds.select(orgSel, r=True)
    return vertData


#11

Castius that script is doing nothing here…
is there a special trick…?


#12

Thanks, man! Works great )) It’s exactly what I was looking for.


#13

oglu does that script still not work for you?


#14

still nothing… i have no clue…


#15

Yeah for some reason it’s not working for me either. But in my case I am sure I am doing something wrong.


#16

It seems two spaces slipped in your code.

change this:

data = {'vertex':vert,'vertexPos':pos,'cv':None,'cvPos':N  one}

to:

data = {'vertex':vert,'vertexPos':pos,'cv':None,'cvPos':None}

Now it should work :slight_smile:

Edit:
Okay, for whatever reason the spaces get inserted automatically. :smiley:
There shouldn’t be any between “N” and “one”.

Great script by the way!


#17

wow that is odd. why is the forum inserting an space.

Good find and thanks


#18

WOW!
For some reason doesnt work the zenTools in MaYa 2017 SP5 on this computer.

BUT…
Im looking for a script like this (I guess)
But unfortunately the script doesnt do nothing at all.

I selected 3 Vertex and run the python script.
Nothing happens.
I also select the whole Vertex loop that I need to adjust and nothing happens.

By selecting edges doesnt work either.

Can some body help me?
What Im doing wrong?

Im using MaYa 2017 SP5
Thank you in advance!


#19

With the “ZhCG_Polytools” script you have the command “average line”
(don’t pay attention to the custom menu, it’s the same command)


#20

I dont have that option directly in the submenu like you, but is over the main menu.
I tried all the option that offers and I think we are speaking to a different approach.

If you tried to un-organize your vertex Like the pic below you will never have a perfect arranged vertices like the pic below.

Vertices properly arranged .


#21

well it’s an average function, so it doesn’t really make sense. How it’s supposed to guess the shape you want?
could be this, this or this so…


#22

Sure can do what ever you want.
So needs to be add in the options.

I tried all option that offer that great tool, but nothing like I post.


#23

just create a curve with the shape you want (in your case an arc ) and conform the points to this curve.


#24

How can you conform them in one step?


#25

Somewhere in the ZhCG you have a function for that, here i’m calling it.


#26

Could anyone tell me on which version of maya the ZhCG works? I’m using maya 2016 LT and it doesn’t work at all; it doesn’t even appear on the main menu. Thanks in advance


#27

the tool is written in python and there is no python in maya LT


#28

I can’t find that script anywhere…, all the highend3D links are dead or not working…, Do you have a valid link to download?. Thanks in
advance.


#29

highend3d is working fine here.
try to past this

https://www.highend3d.com/maya/script/zhcg_polytools-for-maya/