to change location of objects

i’m trying to make a script to move the location of selected objects
i used the LocY for instance but it did not work as expected - this gives access to
the N-transform panel location
there must be another way to gain access for instance to the box location
which would move it in absolute value i think
what are the command lines needed to do that in python?

note if there was a Ctrl-A made on an object i think this will stop the LocY to worl properly
because this is not oonger the reel location!

Thanks

You can create IPO Curves using Python to change the location.

The N-transform panel is the actual location in world space. Are you trying to move objects along there local coordinates or there global ones? Also if the objects have parents, then setting the location is relative to the parent.

If you’re trying to move vertexes inside an object, then you need to transform them to global space by multiplying by the object’s matrix. Then they’ll move in absolute coordinates.

I have some python setLocation code here:
http://pasteall.org/176/python
Related to this post:
http://blenderartists.org/forum/showthread.php?t=121608

Rotate code:
http://blenderartists.org/forum/showthread.php?t=113198

Scale code:
http://blenderartists.org/forum/showthread.php?t=113197

it would be nice to have some examples or doc showing how to do what your saying

and what is the difference between local and global
that would be interesting too!

and never seen an example with this matrix to trabnslate inside a mesh that would be interesting too
i’m slowly learning the way python works with blender but it’s not easy
the officiel doc is so fromal and very difficult to follow unless there is a good exanple with it
but it’s not always the case

moving foward but slowly

sorry i dont’ come everyday on this forum!

Thanks

Local versus Global (or world, I use them interchangeably), are basically different coordinate systems. Vertexes can be relative to the objects local coordinate system (this is the default because of how OpenGL works), or to the global one (which is how we get trained to think about coordinates). Without going into too much math, it suffices to say that you can consider local to be relative to the objects center, taking into account its rotation and size, while global is relative to (0,0,0) (the origin).

Here’s a quick demo (make sure you select a mesh object like the default cube):


import Blender
import bpy

scn = bpy.data.scenes.active
ob = scn.objects.active

print ob.getLocation('worldspace')

ob.LocZ += 1

print ob.getLocation('worldspace')

ob.setLocation(0, 2.0, 3.0)

print ob.getLocation('worldspace')


#################
me = ob.getData(mesh = True)

print me.verts[0].co 

# But wait this isn't where this vert is! Actually it is, but its relative
# to the object's center and orientation (rotation/scale). If we want its
# absolute position, lets transform it to global coordinates

obmat = ob.matrix

print me.verts[0].co * obmat

# Now its where we want it to be. Its now in global space, relative to the global
# Origin (or (0,0,0))

Blender.Redraw()

Read the comments, but also try playing around with some stuff. Look in the N-transform panel as you play around with object locations. Try giving the object a parent and see how that effects whats going on.

For the last part, the main thing to note is that you can essentially apply a transform to a coordinate by multiplying by its object’s matrix (you get absolute world coordinates). Most operations can be performed on relative coordinates since most operations are relative (shift along a normal, translate, etc. can all be done without knowing absolute positions). Sometimes, though, its necessary to know these coordinates.

For most purposes, though, its really not all that necessary to worry about world vs. local when your generating meshes. But for some applications, obviously it can be important to know absolute positions, like when you’re dealing with multiple objects where you need to do manipulations between them. In that case, you want to work in global coordinates between the objects.