Hello,
I made this script which allows, after having selected two vertices, to place a new vertex along the line formed by these two vertices. This by indicating a position on one of axes X, Y or Z
import Blender
from Blender import *
global contrainte
global result
def Global_Local (P, Obj, coord):
if coord=="global":
m = Obj.getMatrix()
if coord=="local":
m = Obj.getInverseMatrix()
PX = P[0]*m[0][0] + P[1]*m[1][0] + P[2]*m[2][0] + m[3][0]
PY = P[0]*m[0][1] + P[1]*m[1][1] + P[2]*m[2][1] + m[3][1]
PZ = P[0]*m[0][2] + P[1]*m[1][2] + P[2]*m[2][2] + m[3][2]
return [PX,PY,PZ]
edMode = Window.EditMode()
Window.EditMode(0)
obj = Blender.Object.GetSelected()
mesh = obj[0].getData(mesh=1)
if obj == []:
result = Draw.PupMenu("Vous devez sélectionner un objet")
elif obj[0].getType() != "Mesh":
result = Draw.PupMenu("Vous devez sélectionner un mesh")
else:
VertSel = mesh.verts.selected()
if len(VertSel)!=2:
Draw.PupMenu ('Vous devez sélectionner 2 vertices')
else:
repert = "Coordonées :%t|Local|Global"
resultrepert = Draw.PupMenu (repert)
if resultrepert != -1:
if resultrepert ==1:
Pt1 = mesh.verts[VertSel[0]].co
Pt2 = mesh.verts[VertSel[1]].co
else:
Pt1 = Global_Local (mesh.verts[VertSel[0]].co,obj[0],"global")
Pt2 = Global_Local (mesh.verts[VertSel[1]].co,obj[0],"global")
coord2=[]
axe="Axe :%t"
if abs(Pt1[0]-Pt2[0])>0.00001:
axe+="|X"
coord2.append(0)
if abs(Pt1[1]-Pt2[1])>0.00001:
axe+="|Y"
coord2.append(1)
if abs(Pt1[2]-Pt2[2])>0.00001:
axe+="|Z"
coord2.append(2)
if len(coord2)==0:
Draw.PupMenu ('Les 2 vertices ont la meme position !')
else:
if len(coord2)==1:
result = 1
else:
result = Draw.PupMenu(axe)
if result != -1:
result-=1
texte = "Coord " + axe[8+result*2] +":"
contrainte=Draw.PupFloatInput (texte,0,-10000,10000,100,4)
if contrainte != None:
if abs(Pt1[coord2[result]]-contrainte)<0.001 or abs(Pt2[coord2[result]]-contrainte)<0.001:
Draw.PupMenu ('Le point existe déja')
else:
t=(contrainte-Pt1[coord2[result]])/(Pt2[coord2[result]]-Pt1[coord2[result]])
x3=Pt1[0]+t*(Pt2[0]-Pt1[0])
y3=Pt1[1]+t*(Pt2[1]-Pt1[1])
z3=Pt1[2]+t*(Pt2[2]-Pt1[2])
if resultrepert ==1:
Pt3 = [x3,y3,z3]
else:
Pt3 = Global_Local ([x3,y3,z3],obj[0],"local")
ed = mesh.edges.selected()
if len(ed)==1:
g = [x3,y3,z3]
dist1 = abs(Pt1[coord2[result]]-Pt2[coord2[result]])
dist2 = abs(Pt1[coord2[result]]-g[coord2[result]])
dist3 = abs(Pt2[coord2[result]]-g[coord2[result]])
if dist1>dist2 and dist1>dist3:
mesh.subdivide()
VertSel = mesh.verts.selected()
mesh.verts[VertSel[2]].co[0]=Pt3[0]
mesh.verts[VertSel[2]].co[1]=Pt3[1]
mesh.verts[VertSel[2]].co[2]=Pt3[2]
else:
mesh.verts.extend(Pt3[0],Pt3[1],Pt3[2])
VertSel = mesh.verts.selected()
if dist2>dist3:
mesh.edges.extend(VertSel[1],VertSel[2])
else:
mesh.edges.extend(VertSel[0],VertSel[2])
else:
mesh.verts.extend(Pt3[0],Pt3[1],Pt3[2])
if edMode: Window.EditMode(1)
Blender.Redraw()
There still remains a thing to be made but which is not essential: when the new point this finds apart from the 2 vertices selected, and that this new point is on an existing edge it would be necessary that this edge is subdivided…