How to scale a mesh

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Beauty
Posts: 0
Joined: Wed Nov 28, 2007 4:29 pm
Location: Germany

How to scale a mesh

Post by Beauty » Fri Dec 10, 2010 3:24 pm

Hi

The background:

On yesterday I wrote my first python script for blender which removes/replaces redundant material definitions.
It works fine and I'm happy, because it does a great job. Before I used some hours of work and now the script does it automatically in just 5 minutes.

Now I want to write a script which scales all meshes of my scene.
It's easy to do in the object mode (select all and resize).
But I need to scale the meshes directly (in edit mode), because my model exporter uses the mesh dimensions.
My problem is that I can't select/scale all meshes together in edit mode.
There is a need to scale each single mesh (in edit mode), but I have more then 1000 meshes, which is not usable for manual scaling.


My question:

I need to know how to scale a mesh (in edit mode) by the Blender API. (Blender version 2.49b)

Unfortunately I couldn't find out the right properties of the Mesh class.
(Maybe I need do it by scaling the position values of the vertices?)

Here is an example how to get access to the name, material and vertices of a mesh.

Code: Select all

myMesh = Mesh.Get()[0]  # get a random mesh

# access to properties:
myMesh.name
myMesh.materials
myMesh.verts
But I can't find something like myMesh.scale.

I searched in the web and in different scripts for more than one hour. Also in the Blender API documentation I couldn't find help.

Any idea how to scale a mesh?

ldo
Posts: 0
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Post by ldo » Fri Dec 10, 2010 11:22 pm

There is no mesh.scale, or anything like that. There is an overall object matrix, which maps the vertices from object-local coordinates to global coordinates.

If you want to alter the coordinates of each mesh vertex, then you do that by assigning a new Vector value to the .co field of each MeshVertex. Compute the new value by multiplying the old one by a suitable Matrix that applies the scaling (or whatever other transformation) you want.

Don’t forget to call the mesh’s .update method when you’re done.

Post Reply