Very simple script

Hi
I’m completely new to blender scripting.
I want to make maps with roads. I am trying to find a way to make the roads “flat” (still climbing hills etc, not rotating).
This could be done by scaling the road to 0 in the z direction, but that would eliminate all elevation.

I want to select the edges crossing the road and scale them to 0 in the z direction one by one.

This is the script
It runs, but nothing happens.

import Blender
 
Blender.Window.EditMode(1)
 
obj = Blender.Object.GetSelected()[0]
 
me = obj.getData(mesh=1)
 
 
for edge in me.edges:
  z_ = (edge.v1.co.z + edge.v2.co.z) * 0.5
  edge.v1.co.z = z_
  edge.v2.co.z = z_
 
Blender.Redraw()

is your camera directly above your “map”?

you can change the camera to orthographic view - that way everything appears the same size and doesn’t get smaller when it is further away or closer.

might help?

nope, doesn’t help

You are missing the command to update the mesh. Try adding me.update() before last redraw. Also you could do check for the mode like:


inEmode = Blender.Window.EditMode()
if inEmode: win.EditMode(0)

#code here

me.update()

if inEmode:
  win.EditMode(0)
  win.EditMode(1)

Blender.Redraw()

Hi,

Take a peek at the Auto Align Vertices code found at: http://www.davidjarvis.ca/blender/tools/

Hope it helps!

This is the code now, it works, but it affects the whole object.
How to affect only selected edges?

Thanks

import Blender

inEmode = Blender.Window.EditMode()
win = Blender.Window
if inEmode: win.EditMode(0)

obj = Blender.Object.GetSelected()[0]
me = obj.getData(mesh=1)
 
 
for edge in me.edges:
  z_ = (edge.v1.co.z + edge.v2.co.z) * 0.5
  edge.v1.co.z = z_
  edge.v2.co.z = z_

me.update()

if inEmode:
  win.EditMode(0)
  win.EditMode(1)

Blender.Redraw()

EDIT: found it out

import Blender

inEmode = Blender.Window.EditMode()
win = Blender.Window
if inEmode: win.EditMode(0)

obj = Blender.Object.GetSelected()[0]
me = obj.getData(mesh=1)

edges = [edge for edge in me.edges if edge.sel] 
 
for edge in edges:
  z_ = (edge.v1.co.z + edge.v2.co.z) * 0.5
  edge.v1.co.z = z_
  edge.v2.co.z = z_

me.update()

if inEmode:
  win.EditMode(0)
  win.EditMode(1)

Blender.Redraw()