Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

May 22, 2011

Blender 2.5 Python 3.2 Vector Translate Euler

updated 21 september 2012 for blender 2.6.

Hoping to figure this thing out in more detail, here's a snippet that seems to work. It also gives most basic insight into how to translate a Vector using Euler (transform?)
import bpy
from mathutils import Vector, Euler

myTrans = Vector((0.0,0.0,.5))
myEuler = Euler((0.0, 0.3, 0.0),'XYZ')
for i in range(14):
    myVec = Vector((0.0, 0.3, 0.0))
    bpy.ops.mesh.extrude_region_move(TRANSFORM_OT_translate={"value":myTrans})
    bpy.ops.transform.rotate(value=(0.3,), axis=myVec)
    myTrans.rotate(myEuler)


- Add a new circle
- select the edges
- run the script.



Here is a slight modification, it produces a spiral
import bpy
from mathutils import Vector, Euler

myTrans = Vector((0.0,0.0,.5))
myEuler = Euler((0.2, 0.3, 0.0),'XYZ')
for i in range(34):

    myVec = Vector((0.2, 0.3, 0.0))
    bpy.ops.mesh.extrude_region_move(TRANSFORM_OT_translate={"value":myTrans})

    bpy.ops.transform.rotate(value=(0.35,), axis=myVec)
    myTrans.rotate(myEuler)    



while, the one below produces a more spring like coil.
import bpy
from mathutils import Vector, Euler

translation = Vector((0.0, 0.0, .5))

for i in range(134):
    t_dict = {"value": translation}
    bpy.ops.mesh.extrude_region_move(TRANSFORM_OT_translate=t_dict)
    bpy.ops.transform.rotate(value=(0.358,), axis=Vector((0.2, 0.3, 0.0)))
    translation.rotate(Euler((0.2, 0.3, 0.0),'XYZ'))
    

i applied some subsurf to it later.

4 comments:

  1. Using the script is not yet possible
    you get an error of poll: wrong context.

    ReplyDelete
  2. the screen shots are evidence of the contrary.
    - be in edit mode with the edges of the shape selected, then run the script.

    ReplyDelete
  3. Is there any way to apply the rotation so that you can see the results step by step before the script finishes. I can change rotation but nothing happens until the script has ended.

    ReplyDelete
    Replies
    1. Not with the code I provided, but i've been meaning to write a 'modal' operator that allows you to adjust sliders for the desired variables in real-time, before 'accepting' the geometry.

      A good place to start is the Cube Mesh operator template in the Text Editor menu. If i have time and can figure out a clean way to do this, i'll write a post about it.

      Delete

Please use Blender.StackExchange.com for python scripting questions unrelated to this post.