Page 1 of 1

Transforming with Python

Posted: Thu Dec 08, 2005 4:52 am
by Rick3D
Can a python script call functions within Blender to rotate or transform selected objects or vertices rather than calculate the transformations itself. It would be nice to have a rotate(...), move(...) and scale(...) function. These are all things that Blender already knows how to do and it does them well. Access to other features such as extrude, mirror, etc. would be pretty cool too.



Posted: Thu Dec 08, 2005 5:12 am
by khughes
You can control an object's size, rotation and location using the size, rot and loc attributes:

Code: Select all

import Blender

for obj in Blender.Object.GetSelected():
    print 'name is ',
    print '  location = ',obj.loc
    print '  rotation = ',obj.rot
    print '  size        = ',obj.size
The rotation gives the Euler angles (currently in radians).

You can assign tuples to these attributes, which will change the object's values. You can also access the attributes individually; for example, LocX is the x value of the location.

As far as I know, there is nothing in the BPython API to access things like mirror, extrude, etc.

Posted: Thu Dec 08, 2005 10:41 am
by Rick3D
Thanks khughes. If I understand correctly, size, loc and rot would be used to transform the entire object but not, for example, a set of individually selected vertices. What I had in mind was a function that could work on any number of selected objects or vertices as a set, taking delta x, y and z or scale and rotation values as arguments.

something like...

move(deltax, deltay, deltaz)
scale(factorx, factory, factorz)
rot(rotationx, rotationy, rotationz, pivot)

I suppose I could write Python functions for this, then I would have what I'm looking for. I'll need to spend a little more time with Python, though. Just being lazy, I guess.



Posted: Thu Dec 08, 2005 5:47 pm
by khughes
You're right, there isn't anything which transforms individual or sets or vertices. Although you can use the Mathutils modules to build matrices which you can then use to transforms vertices in a script.

Posted: Thu Dec 08, 2005 8:34 pm
by LetterRip

that might be something good to have as examples with the transform function.