Previous Thread  Next Thread

chat icon Center origin using python script for Blender 2.49b

sezys

Posted: Tue Jun 26, 2012 6:16 am
Joined: 26 Jun 2012
Posts: 1
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:\..........."
os.chdir(pth1)
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 = bpy.data.scenes.active
context = scn.getRenderingContext()
context.extensions = True
context.renderPath = "//"
context.imageType = Render.BMP
context.sizeX = 480
context.sizeY = 480
lo = list(scn.objects)
print(lo)
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()
#print(msh)
#msh = list(bpy.data.meshes)
# mymsh = msh[len(msh)-1]
for face in mymsh.faces: face.smooth=1
Window.EditMode(1)
verts = mymsh.verts[:]


#mymsh.transform(myobj.matrix)
for v in verts:
v.co[1]-=50

mymsh.verts = verts
mymsh.update()

Blender.Redraw()
mtrl = mymsh.materials[0]
mtrl.rgbCol = [0.5,0.5,0.5]
mtrl.setSpecShader(1)
mtrl.setSpec(2)




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,Cool
one2twenty = range(1,20)
one2thirtyeight = range(1,3Cool
one2seventythree = range(1,73)
one2onehundredtwentytwo = range(1,122)
one2onehundredeightytwo = range(1,182)

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

# myobj.RotZ = 3.14159+3.14159/4



scn.unlink(myobj)
obs = scn.objects
del scn


I am a beginner with Python for Blender so any help would be appreciated.
Thanks!!!
Reply with quote


CoDEmanX

Posted: Tue Jun 26, 2012 6:35 am
Joined: 05 Apr 2009
Posts: 692
this relates to 2.63, but maybe gives a hint:
http://projects.blender.org/tracker/?func=detail&atid=498&aid=31640&group_id=9
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group