Selecting vertices using python?

Hi,
I’ve made a terrain and I’ve got thousands of trees on it using dupliverts. It renders quickly because I’m using textured planes that turn to point at the camera as trees. (see pic) They look repetitive though since they all use the same texture and are the same size.
I want to split the duplivert mesh into a few (e.g. 5) separate meshes. Each mesh would then use a different textured plane for its dupliverts. To do that manually (with the thousands of vertices involved) would take a really long time…
If I did it in python it wouldn’t take very long… maybe the easiest way would to be to do it like this…

  1. select mesh
  2. enter edit mode (tab)
  3. select all the vertices, use hash (randomizes the vertex indices?), unselect all the vertices
  4. run script (alt-p?) so that the first 1/5 (length/5) vertex indices are selected in edit mode
  5. press p to separate the selected (1/5) vertices
  6. edit script so that the first 1/4 (length/4) vertex indices are selected
  7. run script
  8. separate the selected 1/4 vertices
  9. select 1/3 of the remaining vertices (using modifed script)
  10. separate them
  11. select 1/2 of the remain vertices (using the modified script)
  12. separate them.

And then there’d be 5 meshes of approximately equal size which have approximately evenly spread vertices. (Due to the vertex indexes being randomized using the hash button)

Another alternative is to run a script that does all of that automatically…

BTW, so far the only scripts I’ve made involve getting and setting the locations and rotations of things. (But I have done a programming degree at university) I was wondering if anyone can help - I can’t find any information about selecting vertices but I think I read about a method for selecting faces.

Forget it.

Do like me (if you want - http://www.selleri.org/Blender/buffer/tropical.jpg )

Image has only 2 types of tree but a single mesh.

take the mesh where you duplivert.

Duplicate it 4 times (to have 5 different trees)

Make each random via the hash function

Make each a particle emitter with Face on and wit as many particles as it is 1/5 of the vertices

Make partcles start at frame 0 and end at frame 1

make the same for all meshes but with different seeds

Parent and Duplivert.

Voilà

Stefano

S68:
Thanks for that interesting technique… but unfortunately I didn’t find it very helpful for what I want to do. :frowning:
http://members.ozemail.com.au/~wenke/blender/Duplivert-Test01.blend

Here is a test I made using your method. I think it took about as long as if I had did it using python. (Assuming I knew how)

This is what the python script would roughly look like:

import blender stuff

divisionAmount = 5

theMesh = getSelectedMesh
numVertices = length(theMesh)
for i=1 to numVertices/divisionAmount
theMesh.vertex[i].select()

Obviously the exact syntax is wrong but that is just a basic idea of what I think I need.

BTW, S68, besides being inefficient as far as memory goes (the whole 40,000 vertices are duplicated 5 times rather than split into groups of 8000) and probably slows down rendering a bit due to the particles maybe being calculated every frame… but the main problem is that the dupliverts aren’t in different places. Sometimes different trees would occupy the same position, or there would be areas where no trees are.
For each tree position, assuming there are 5 tree-types, I think there would be a (4/5)^5 = 33% chance of no trees, (4/5)^4 = 41% chance of exactly one tree and therefore a 26% chance of there being 2 or more trees on the exact same spot (I think). But I’d like each spot to have exactly 1 tree. Your method looks ok in your picture, but I want to do this for a 3 minute music video and you’d see the trees fairly close up a lot of the time. (I might put the forest more way from the city [erase the vertices where the buildings are], but you’d still see the forest fairly close up some of the time - so there can’t be multiple trees at the same spot).

LukeW, in order to get the “active” object (only one active object, as opposed to selected objects) use the following:

activ = Blender.Object.GetSelected()[0]

Object.GetSelected() returns a list of all the selected objects in the scene. The first object in the list is the active object.

Then do a test to ensure that the object is a Mesh:

if activ.getType() == "NMesh":

If this works, you can then get the mesh out of the object via:

    me = activ.GetData()

For the next step, you probably want to work with vertex data. (I can almost guarantee that the meshes you get from this will have no faces, but as you’re using this for Duplivert placement, it probably won’t matter.)

To get the list of verticies, use the mesh property “verts”:

    verts = me.verts

You may want to change this by making a copy of the verts property, rather than working on the original list, e.g.:

    verts = copy.copy(me.verts)

Hope this helped?

AncientHart

just to say that the “me” object returned by getData() is yet a copy of the original data…

just to say that the “me” object returned by getData() is yet a copy of the original data…

E-oops! :wink: