Merge Points in Plane

I’m doing an architectural model, and for whatever reason I’ve got all sorts of annoying anomolies in points that should all be perfectly vertical (i.e., they should have identical X and Y coordinates, but they differ in Z). I’d love to grab them in a Top view and then do Merge Points To Plane, which would give me options like To First, To Last, Center, etc., but would leave my Z values alone.

Anybody have a script to do this in Python? Or, better yet, does this fit into the priority list of the Blender developers working on improving Blender’s CAD functionality?

Grab them in top view, then use scale to zero to line them up. To scale to zero, press Skey to start scaling, then press Xkey (or Ykey or Zkey) and then press Zero. The vertices will snap to the average X location, and the other values will not be affected. Once lined up in X, you can then line them up in Y.

Not exactly what you’re looking for, since it calculates the zero position rather than letting you specify it. As a work around, you could pick a vertex that is in the correct position and not select it. After the others are lined up, move them to match the reference vertex.

#!BPY
“”" Registration info for Blender menus:
Name: ‘Merge Verticies within XY Plane’
Blender: 237
Group: ‘Mesh’
Tooltip: ‘Merge Verticies within X-Y Plane’
“”"

author = “Michael Tiemann”
url = (“blender”, “elysiun”)
version = “1.0 2006-10-30”

bpydoc = “”"
This script merges all selected points to the X-Y coordinates of the
first point selected. Z values are unaffected.
“”"

***** BEGIN GPL LICENSE BLOCK *****

Copyright © 2006 Michael Tiemann

This program is free software; you can redistribute it and/or

modify it under the terms of the GNU General Public License

as published by the Free Software Foundation; either version 2

of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program; if not, write to the Free Software Foundation,

Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

***** END GPL LICENCE BLOCK *****

--------------------------------------------------------------------------

from Blender import *

def main():
scn = Scene.GetCurrent()
ob = scn.getActiveObject() # Gets the current active object (If Any)

    if ob == None or ob.getType() != 'Mesh': # Checks the active objects a mesh
            Draw.PupMenu('ERROR%t|Select a mesh object.')
            return
    
    Window.WaitCursor(1) # So the user knowns the script is buisy.
    
    is_editmode = Window.EditMode() # Store edit mode state
    if is_editmode: Window.EditMode(0) # Python must get a mesh in object mode.
    
    me = ob.getData()
    
    #================#
    # EDIT MESH HERE #
    #================#
v0 = 0
for v in me.verts:
            if v.sel: # Operating on selected verts is what the user expects.
        if v0 == 0:
            v0 = 1
            x = v.co.x
            y = v.co.y
        else:
            v.co.x = x
            v.co.y = y
    
    #================#
    # FINISH EDITING #
    #================#
    
    me.update() # Writes the mesh back into Blender.
    
    # Go back into editmode if we started in edit mode.
    if is_editmode: Window.EditMode(1)
    Window.WaitCursor(0)

if name == ‘main’: # Dont run the script if its imported by another script.
main()

Your script aligns the selected vertices to whichever vertex comes first in the list of selected vertices, most probably not what you want. To know which vertex is first or last selected, you would need to use scriptlinks.

To align a vertical edgeloop to a given vertex in it, you can snap the cursor to that vertex, press PERIOD to scale around the cursor, press Shift+Z to lock the Z axis only and then press ZERO.

By the way, to show a script in a forum, wrap the script between CODE tags, because otherwise the indentation is lost and the script is useless without it (or select the block of Pyhton code and click on this symbol:http://blenderartists.org/forum/images/editor/code.gif ).