DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Blender 2.49 Transform A Group Of Objects Mesh Data

03.29.2012
| 2716 views |
  • submit to reddit
        
#!BPY

"""
Name: 'Transform ObjData'
Blender: 242
Group: 'Object'
Tooltip: 'Move the verticies'
"""


__author__ = "Adrian Boeing"
__url__ = ("http://www.blender.org", "http://www.transmin.com.au", "http://www.adrianboeing.com")
__version__ = "1.0 26/10/2010"

__bpydoc__ = """\
This script transforms the object data (verticies) inside an object for a group of objects.
(similar to the normal translate with Ctrl-A)

Usage:
Select objects and run this script. 
Type in the transform values and scale value.
Press OK for each object to transform.
"""

# $Id: object_transform.py$
#
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Copyright (C) 2012: Adrian Boeing. http://www.adrianboeing.com/
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****

import subprocess
import bpy
import Blender
from Blender import *
from Blender.Draw import PupFloatInput 

def move_obj(mesh, tx, ty ,tz, scale):
	for vert in mesh.verts:
		vert.co.x = vert.co.x + tx
		vert.co.y = vert.co.y + ty
		vert.co.z = vert.co.z + tz
		vert.co.x = vert.co.x*scale 
		vert.co.y = vert.co.y*scale 
		vert.co.z = vert.co.z*scale 
    
    
def main():
    scn = bpy.data.scenes.active
    obs = scn.objects.context
    tx = PupFloatInput('Translate X', 0.0, -10000,10000, 10, 10000)
    ty = PupFloatInput('Translate Y', 0.0, -10000,10000, 10, 10000)
    tz = PupFloatInput('Translate Z', 0.0, -10000,10000, 10, 10000)
    scale = PupFloatInput('Scale', 1.0, -100,100, 1, 1000)
    for ob in  obs:
        if not ob:
            Blender.Draw.PupMenu('No object selected.')
            return
        if ob.type != 'Mesh':
                Draw.PupMenu("Error%t|Selection must be made up of mesh objects only")
                return
        text = "Transform" + ob.name + "?%t|OK"
        result = Draw.PupMenu(text)
        if result == -1:
            continue
            
        mesh = ob.getData(mesh=1)
        move_obj(mesh , tx, ty ,tz, scale)
    
if __name__=='__main__':
	main()