0

I am new to blender and python. So, I try some examples to see if they are work.

But I encounter a problem when I try to run the script.

AttributeError: 'Vector' object has no attribute 'pop'

I researched the internet and found nothing about it. Is it a problem about the 'pop' or the Blender or even the python?

Sometimes the python warns me about the 'pop' is out of range. Could anyone give suggestion on how to solve this problem? Here is the script in my blender.

import bpy  

current_obj = bpy.context.active_object  

print("="*40)  

for face in current_obj.data.polygons:  

    verts_in_face = face.vertices[:]  

    print("face index", face.index)  

    print("normal", face.normal)  

    for vert in verts_in_face:  

        print("vert", vert, " vert co", current_obj.data.vertices[vert].co)

print("="*40)

coordinate = current_obj.data.vertices[vert].co

print("coordinate = ", coordinate.pop(2))

fo = open("foo.txt", "rw+")

print ("Name of the file: ", fo.name)

# This is 1st line
# This is 2nd line
# This is 3rd line
# This is 4th line
# This is 5th line

str = "This is 6th line"

fo.seek(0, 2)

line = fo.write( str )

fo.seek(0,0)

for index in range(6):

   line = fo.next()

   print ("Line No %d - %s" % (index, line))

fo.close()<i>

2 Answers 2

1

.pop(x) is a method of a Python list, which removes and returns a value from a list at index x.

This is making coordinate a Vector object:

coordinate = current_obj.data.vertices[vert].co

This is treating coordinate like a list:

print("coordinate = ", coordinate.pop(2))

You can read up on the pop() method here: http://docs.python.org/3.2/tutorial/datastructures.html#more-on-lists

0
coordinate = current_obj.data.vertices[vert].co
print("coordinate = ", coordinate.pop(2))

coordinate is a Vector and pop() removes an item from a list. You may want to alter a Vector value but it makes no sense to remove an item from a vector.

Blender offers several ways to access the data in a Vector -

# like an array
coordinate.[0]
# most will contain 3 items but 4d Vectors are used in some situations.
len(coordinate)
# get a specific item
coordinate.y
# get a combination of elements - many variations available - xyz zyx yzx ....
coordinate.xyz
# each of these can be returned as a tuple instead of a vector
coordinate.to_tuple()
coordinate.xyz.to_tuple()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.