Center origin using python script for Blender 2.49b

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Posts: 1
Joined: Tue Jun 26, 2012 7:10 am

Center origin using python script for Blender 2.49b

Postby sezys » Tue Jun 26, 2012 7:16 am

Hi all,
I am having problems finding the correct command to center the origin of my object using Python 2.5.2 for Blender 2.49b.
I have a script that imports obj(faces) and then rotates it taking still images at regular increments. Normally this works fine, but I have received some different objs that come into Blender in a completely different position i.e. the center of origin is in the correct place but the mesh is way off to the left. The script is designed so that the face rotates around it's own center of origin, which is located just behind the face, which has worked for all previous data I have used.

So can anyone help me to find the correct command line for either centering the origin in the mesh or better still, allowing me to define where the center of origin should be in relation to the mesh? I have found commands for later versions but not for 2.49b. Below is the script;

import Blender
import bpy
from Blender import *
import os
import glob
import import_obj
import math

pth1 = "C:\..........."
f = glob.glob("*.obj")

myCam = Blender.Object.Get("Camera")
mylamp = Blender.Object.Get("Lamp")

for a in f:
fn = pth1 + "/" + a
import_obj.load_obj(fn, 10)
from Blender.Scene import Render
scn =
context = scn.getRenderingContext()
context.extensions = True
context.renderPath = "//"
context.imageType = Render.BMP
context.sizeX = 480
context.sizeY = 480
lo = list(scn.objects)
myobj = Blender.Object.Get(lo[0].name)

is_editmode = Window.EditMode() # Store edit mode state
if is_editmode: Window.EditMode(0) # Python must get a mesh in object mode.

mymsh = myobj.getData()
#msh = list(
# mymsh = msh[len(msh)-1]
for face in mymsh.faces: face.smooth=1
verts = mymsh.verts[:]

for v in verts:[1]-=50

mymsh.verts = verts

mtrl = mymsh.materials[0]
mtrl.rgbCol = [0.5,0.5,0.5]

mylamp.LocZ = 10
mylamp.LocY = 10
mylamp.LocX = 10
mylamp.RotX = 3*3.14159/2+math.pi/6
mylamp.RotZ = 0 #3.14159/4
mylamp.RotY = 0

#TEST stimuli
myobj.LocX = 0
myobj.LocY = -1
myobj.LocZ = 0
myobj.RotX = math.pi/18
myobj.RotZ = 3.14159+3.14159/2
myCam.RotX = 3*3.14159/2
myCam.RotY = 3.14159

myCam.LocZ = 0
myCam.LocX = 0
myCam.LocY = 5

one2three = range(1,4)
#one2seven = range(1,8)
one2twenty = range(1,20)
one2thirtyeight = range(1,38)
one2seventythree = range(1,73)
one2onehundredtwentytwo = range(1,122)
one2onehundredeightytwo = range(1,182)

for i in one2onehundredtwentytwo:
yang = 600-(i-1)*15
imname = a[:-4]+ "vy"+`yang`
myobj.RotZ -= 3.14159/120

# myobj.RotZ = 3.14159+3.14159/4

obs = scn.objects
del scn

I am a beginner with Python for Blender so any help would be appreciated.

Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Tue Jun 26, 2012 7:35 am

this relates to 2.63, but maybe gives a hint: ... group_id=9
I'm sitting, waiting, wishing, building Blender in superstition...

Return to “Python”

Who is online

Users browsing this forum: No registered users and 0 guests