How to use python script to move and rotate an object in blender?

Hi everyone,
I just start to learn blender. I have added pipe joint python script into blender:

I can create a pipe joint, say elbow joint, with the script:

elbow_joint = bpy.ops.mesh.primitive_elbow_joint_add

I want to use python script to rotate the “elbow_joint” and move it to a new location. So I can create a pipe system.

Can anybody drop several lines of python script here? So I can start the coding from there.

Thanks a lot in advance.


The code is different depending upon what version of Blender you are using.

Do a search in the python forum and you will find your couple of lines of code.

Finally, I found a way to do it. I am not sure it is a good way or not but it works so far.
The demo script is as follows.

from bpy import context
from math import sin, cos, radians
cursor = context.scene.cursor_location
radius = 10
anglesInRadians = [radians(degree) for degree in range(0,360,36)]

for theta in anglesInRadians:
x = cursor.x + radiuscos(theta)
y = cursor.y + radius
z = cursor.z = [x,y,z]
context.active_object.rotation_euler = [theta,0,0]


I could be completely mistaken, but don’t you mean

y = cursor.y + radius*sin(theta)


can you clarify what your doing here !

the pipe joint command in first post

are theses added to the pipe joint script or in another script

and do you have to start the pipe script joint first or not ?