Transforming with Python

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Rick3D
Posts: 0
Joined: Tue Dec 06, 2005 2:15 am

Transforming with Python

Post 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.

Thanks,

Rick

khughes
Posts: 0
Joined: Sat Jan 08, 2005 9:30 pm
Location: Northern California

Post 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 ',obj.name
    print '  location = ',obj.loc
    print '  rotation = ',obj.rot
    print '  size        = ',obj.size
    print
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.

Rick3D
Posts: 0
Joined: Tue Dec 06, 2005 2:15 am

Post 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.

Thanks,

Rick

khughes
Posts: 0
Joined: Sat Jan 08, 2005 9:30 pm
Location: Northern California

Post 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.

LetterRip
Posts: 0
Joined: Thu Mar 25, 2004 7:03 am

Post by LetterRip »

ken,

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

LetterRip

Post Reply