搅拌机和蟒蛇的困境

时间:2014-03-21 19:49:13

标签: python blender

我是blender和python的新手。所以,我尝试了一些例子,看看它们是否有用。

但是当我尝试运行脚本时遇到问题。

AttributeError:' Vector'对象没有属性' pop'

我研究了互联网并没有发现它。是关于“流行音乐”的问题吗?还是Blender甚至是python?

有时候蟒蛇会警告我关于“流行音乐”的问题。超出范围。谁能提出如何解决这个问题的建议?这是我的搅拌机中的脚本。

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 个答案:

答案 0 :(得分:1)

.pop(x)是Python list的一种方法,它从索引x的列表中删除并返回一个值。

这使coordinate成为一个Vector对象:

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

这就像coordinate一样list

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

您可以在此处阅读pop()方法:http://docs.python.org/3.2/tutorial/datastructures.html#more-on-lists

答案 1 :(得分:0)

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

coordinate是一个Vector,pop()从列表中删除一个项目。您可能想要更改Vector值,但从向量中删除项是没有意义的。

Blender提供了几种访问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()
相关问题