looks like (for me) this is the final version,

its for blender-2.61 (may work the same with blender.2.60/2 but not tested).

a screenshot to show the square-rotated-extrusion

and before the next extrusion is made, its still necessary to do

a remove-double-vertices, because the rotation creates duplicated vertices

in the “knee” of the corner.

(edit: the blend-file here should be the new one … dont know how to delete/update old upload? any hints?)

to look only at the coding:

```
# test-dr / 12-06-06 version with calc.of scale sin(pi/4)
# testing some kind of square-90-degrees-rotation
# with the help of the rotate-function (only 2 steps)
# and later scaling to fit for a square-shape
#
# uses position of 3d-curser (rotation-center) and view-axis for rotation-axis
# set 3d-curser with shift-s to desired place
import bpy
from mathutils import Vector
from math import sqrt, atan, pi, sin
def adjustvert_co(lp1, lp2, co):
#try to calculate the rotation-point and
# and a first scale along this vector to move to square-position
# print(lp1, lp2, co)
x1,y1,z1 = lp1 # first point of rotation-line
x2,y2,z2 = lp2 # axis/direction of line from first point
#caluclate second point of line for line-equation like: p = p1 + u(p2-p1)
x2 += x1
y2 += y1
z2 += z1
x3,y3,z3 = co # the rotated point-coords, calc nearest point on rotation-axis
# u = position on line according to line-equation
u = (x3-x1)*(x2-x1)+(y3-y1)*(y2-y1)+(z3-z1)*(z2-z1)
print("u:",u)
# calculate point on rotation-axis
x0 = x1 + u * (x2-x1)
y0 = y1 + u * (y2-y1)
z0 = z1 + u * (z2-z1)
# calculate vector to do the scaling along
xn = (co[0] - x0)
yn = (co[1] - y0)
zn = (co[2] - z0)
len = sqrt( xn*xn + yn*yn + zn*zn ) #length?
print("old:", co[:])
if len < 0.00001:
return( co[:] ) # no changes
print("line-intersection:", x0,y0,z0)
print("old:", co[:])
sc = len/sin(pi/4) #calculate strech/scale for 46-degrees angle
co2 = [ x0 + sc*xn/len, y0 + sc*yn/len, z0 + sc*zn/len ]
print("new:", co2)
return(co2)
def main(context):
ob = context.active_object
if ob:
print(ob.name)
if ob.type == "MESH":
mesh = ob.data
nv = len(mesh.vertices)
print(nv, "no. vertices")
center = (0,0,0)
center = context.scene.cursor_location
view_mat3 = context.space_data.region_3d.view_matrix.to_3x3()
y_axis = Vector([0,0,1]) #y-axis
axis = y_axis * view_mat3
bpy.ops.object.mode_set(mode="OBJECT")
vselect=[] #do i need the old selected vertices?
for v in mesh.vertices:
if v.select:
vselect.append(v.index)
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.spin(steps=2, dupli=False, degrees=90, center=center, axis=axis)
#mesh.update()
bpy.ops.object.mode_set(mode="OBJECT")
bpy.ops.object.mode_set(mode="EDIT")
nv2 = len(mesh.vertices)
print(nv2, "no. vertices new")
bpy.ops.object.mode_set(mode="OBJECT")
# loop thru all edges to find vertices, based on connection to the selected verts
for e in mesh.edges:
tryit = False # is a selected vert part of the edge
if mesh.vertices[e.vertices[0]].select or mesh.vertices[e.vertices[1]].select:
tryit = True
if tryit:
# print(e.vertices[:])
for i in e.vertices: #only need stretch/scale of not selected verts
if mesh.vertices[i].select == False:
print("-->", i)
#try adjust like scaling relativ to rot-axis
# print(i, mesh.vertices[i].co[:])
co = adjustvert_co(center, axis, mesh.vertices[i].co[:] )
for k in range(3):
mesh.vertices[i].co[k] = co[k]
bpy.ops.object.mode_set(mode="OBJECT")
bpy.ops.object.mode_set(mode="EDIT")
print("p1 center:", center)
print(view_mat3)
print("y_axis:",y_axis)
print(y_axis * view_mat3)
class SimpleOperator(bpy.types.Operator):
'''Tooltip'''
bl_idname = "object.testspin"
bl_label = "test spin"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
main(context)
return {'FINISHED'}
def register():
bpy.utils.register_class(SimpleOperator)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
if __name__ == "__main__":
register()
# test call
# bpy.ops.object.testspin()
```

for the screenshot, this was slightly rotated to display the resulting mesh better,

the script uses the view-axis for the rotation-axis thru the 3d-cursor and has to be

along the selected faces/vertices, that should be rotated around …

### Attachments

pyops_rot.blend (96.4 KB)