Moving points

Hi,

I am very new to scripting Blender in Python. I am a phd student in fluid dynamics, and would like to create my geometries in Blender, and the number crunching will be done by http://www.opencfd.co.uk/openfoam/, a great open source CFD code.

Since it seems a daunting task, I would just like to ask to know how, givin the nale of an object, the coordinate of its vertices can be moved, one at a time with different value. So, I would like to know how to:

  1. have this object identified in Python
  2. loop over its vertices
  3. apply a translation which depend of current.

Even vague hints, keywords, etc … would help be starting.

Cheers !

you are alot smarter than me but you said even vauge hints so ill give it my best shot. have you looked at this page yet? http://wiki.blender.org/index.php/Doc:Manual/Physics/Fluids

Thanks,

however, what I am looking for, even if used for fluid dynamics, is primarily information on vertices manipulation through Python in Blender.

Vertex manipulation in python can be accomplished as such:


import bpy

# Name of object
obName = "MyObject"

# Get Current Scene
scn = bpy.data.scenes.active

# Get the object I want from the scene
nOb = [o for o in scn.objects if o.name == obName][0]

# Grab the mesh data from that object
me = nOb.getData(mesh = True)

# Loop through the verts and set their coordinates
for v in me.verts:
     v.co = [myXCo, myYCo, myZCo]

If you want to animate this, then you’ll need to look into Script links.

Thanks,

I had this error:

Traceback (most recent call last):
File “Text.001”, line 17, in <module>
TypeError: expected vector argument of size 3

but I modified the lasts lines using

for v in me.verts:
v.co[0] = v.co[0]+0.1
v.co[1] = v.co[1]+0.1
v.co[2] = v.co[2]+0.1

And it works. I do not know how to deal with those vectors objects directly: “print v.co” gave me: 1.000000, 1.000000, -1.000000.

Now, another problem: v.co[] returns me local coordinates, but I would need global ones. How can I do this ?

More precisely: I need to get global coordinates, apply a modification on them, then store the modified variables in the object (this step might need to convert back to local coordinates).

I tried this:


modifObjectDataMat = modifObject.mat # Matrix to transform to global coordinates

for v in modifObjectData.verts: # Loop through the verts of object to set their coordinates
    print 'local: '+str(v.co)
    v.co = v.co * modifObjectDataMat # Conversion to global coordinates
    print 'global: '+str(v.co)
    v.co = v.co * modifObjectDataMat.invert() # Conversion back to local coordinates

But when I compare the global coordinates output in console with the ones output by the ‘Transform Properties’ box, only 3 vertices out of 6 in my test geometry are valid.

You’re inverting the matrix over and over again - so every second vertex will end up wrong.
Try to invert the matrix only once:


modifObjectDataMat = modifObject.mat.copy() # I usually make a copy, just in case...
modifObjectDataMat_inv = modifObject.mat.copy(); modifObjectDataMat_inv.invert()
for v in modifObjectData.verts: # Loop through the verts of object to set their coordinates
    print 'local: '+str(v.co)
    v.co = v.co * modifObjectDataMat # Conversion to global coordinates
    print 'global: '+str(v.co)
    v.co = v.co * modifObjectDataMat_inv # Conversion back to local coordinates

Michael

You may want to visit this thread. I just tackled moving points inside a curve using shape keys all generated from python.

http://blenderartists.org/forum/showthread.php?t=149736