Need help with creation of the script which could read particular edge length of the rectangular planes. Need to recognize which length is the width (just edges pointed in x) and which one height(just edges pointed in z). These values i would like to store as the width and height variables(dimension of the plane). All planes are oriented in the same direction (width will be always x and height always z) but there are thousands of them. Then i would need to use these width and height as the coordinates for UVs for each point of each polygon. x=width, y=height so i will get just one single point for whole rectangle.
I tried to investigate how it would be possible and i found two scripts one for reading lengths for all edges and second one for writing UV coordinates. Everything could be possible to do just in edit mode after i will choose correct UVlayer. The second script works fine for me just i need to implement somehow the recognizin of the length and height values for each rectangle.
Reading edge lengths
import bpy
import bmesh
object = bpy.context.active_object
bm = bmesh.from_edit_mesh(object.data)
for edge in bm.edges:
length = edge.calc_length()
print("length:",length)
Writing UV coordinates for each vertex
import bpy
import bmesh
obj = bpy.context.active_object
me = obj.data
bm = bmesh.from_edit_mesh(me)
uv_layer = bm.loops.layers.uv.verify()
# adjust uv coordinates
for face in bm.faces:
for loop in face.loops:
loop_uv = loop[uv_layer]
# use xy position of the vertex as a uv coordinate
loop_uv.uv = loop.vert.co.x
bmesh.update_edit_mesh(me)
EDIT: I tried to implement this calculation into my code but still i dont know how can i get the desired width and length of the ractangle. In below code a wanted just simply to print these values but without success. Is there something what i missed?
import bpy
import bmesh
import mathutils
obj = bpy.context.active_object
me = obj.data
bm = bmesh.from_edit_mesh(me)
bm.edges.ensure_lookup_table()
x = mathutils.Vector((1,0,0))
for edge in bm.edges:
edges_x = []
edges_z = []
v = edge.verts[0].co - edge.verts[1].co
if abs(v.dot(x)) < .0001:
edges_z.append(edge)
else:
edges_x.append(edge)
width = edges_x.calc_length()
height = edges_z.calc_length()
print(width)
print(height)
```