1
$\begingroup$

The following is a script that is supposed to access UV info but it fails right away in both Object and Edit modes. I fist tried using Bl-2.69.8, then 2.69 then 2.68 and it happens the same every time. I've also tried adding bpy. to the beginning of context but the result is the same.

Can anyone clear this up?

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Should be bpy.context, it's probably treating context as a unique val which is not defined. $\endgroup$
    – iKlsR
    Jan 21, 2014 at 9:53

1 Answer 1

9
$\begingroup$

What you're looking for is bpy.context, so the first line should be:

obj = bpy.context.active_object

It refers to the bpy module being imported in the first line.

You can also use this at the beginning of your scripts:

import bpy
from bpy import context

The entire script should look like this:

import bpy
import bmesh

ob = bpy.context.object
me = ob.data
bm = bmesh.from_edit_mesh(me)

uv_layer = bm.loops.layers.uv.verify()
bm.faces.layers.tex.verify()

for f in bm.faces:
    for l in f.loops:
        luv = l[uv_layer]
        if luv.select:
            luv.uv = l.vert.co.xy

bmesh.update_edit_mesh(me)
$\endgroup$
1
  • 3
    $\begingroup$ @MarcClintDion bpy, not .bpy. Dot not preceded by identifier (accessor), or succeeded by number (floating point), is syntax error. $\endgroup$
    – Adhi
    Jan 22, 2014 at 23:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .