我是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>
答案 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()