Selection of points with x-coordinate maximum

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Akihisa
Posts: 0
Joined: Sun Jun 23, 2013 12:57 pm

Selection of points with x-coordinate maximum

Post by Akihisa » Sun Jun 23, 2013 1:02 pm

Hello, so here is my problem ...

For a personal project, I need for example on a cube that would have made ​​a rotation along z angle of PI / 4 to write a python program that will permit to select the points that have the maximum x coordinate, i mean that for example if you made ​​a list of all the x-coordinate of the vertices constituting the cube, and well most of this list will be the x-coordinate of the point I wish to select. Here is the code I use on a cube:

def sectionner1():
tx = []
truc = bpy.context.scene.objects.active
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action = 'DESELECT')
bm = bmesh.from_edit_mesh(truc.data)
for vert in bm.verts:
tx.append(vert.co[0])
print("+++",maximum(tx))
for vertices in bm.verts:
tx.append(vert.co[0])
if vertices.co[0] == maximum(tx):
vertices.select = True
print(vertices.co)
bpy.ops.mesh.select_all(action ='INVERT')
bpy.ops.mesh.delete(type='VERT')
bpy.ops.object.editmode_toggle()

It selects me the good part when I'm not turning my cube, but once I made ​​a rotation, and although it does not give the correct result anymore ... If someone has a solution!

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Sun Jun 23, 2013 4:47 pm

A couple hints:

* using the Code tag will preserve indentation and keep your python code readable.

* Blender objects consist of two parts, Object and ObData.

The Object part holds spatial information - location, rotation, and scale (along with some other stuff)

The ObData part holds the geometry - points, edges, faces.

The logic behind this design is that the ObData (geometry) can be shared by many Objects, what Blender calls Linked Duplicates. Think about a row of street lights, all the same geometry, differing only in location.

What this means is to get world coordinates for your rotated objects, you must either apply the Object's matrix to the ObData points or use the Apply function (CTL-A in Object Mode) to move the Object transformation into the ObData.

Akihisa
Posts: 0
Joined: Sun Jun 23, 2013 12:57 pm

Post by Akihisa » Sun Jun 23, 2013 5:00 pm

stiv wrote:A couple hints:

* using the Code tag will preserve indentation and keep your python code readable.

* Blender objects consist of two parts, Object and ObData.

The Object part holds spatial information - location, rotation, and scale (along with some other stuff)

The ObData part holds the geometry - points, edges, faces.

The logic behind this design is that the ObData (geometry) can be shared by many Objects, what Blender calls Linked Duplicates. Think about a row of street lights, all the same geometry, differing only in location.

What this means is to get world coordinates for your rotated objects, you must either apply the Object's matrix to the ObData points or use the Apply function (CTL-A in Object Mode) to move the Object transformation into the ObData.
YES!!! My problem is solved. I knew it wasn't complicated but something was missing in my code and it was just the CTRL-A! Thank you soooooo much !!! I got it now ^^

Post Reply