[英]A plight in blender and python
我是搅拌机和python的新手。 因此,我尝试一些示例,看看它们是否有效。
但是,当我尝试运行脚本时遇到了问题。
AttributeError:“ Vector”对象没有属性“ pop”
我研究了互联网,却一无所获。 是关于“ pop”或Blender甚至是python的问题吗?
有时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>
.pop(x)
是Python list
一种方法,该方法从列表的索引x处删除并返回一个值。
这使coordinate
成为Vector对象:
coordinate = current_obj.data.vertices[vert].co
这就像list
一样对待coordinate
:
print("coordinate = ", coordinate.pop(2))
您可以在此处阅读pop()
方法: http : //docs.python.org/3.2/tutorial/datastructures.html#more-on-lists
coordinate = current_obj.data.vertices[vert].co
print("coordinate = ", coordinate.pop(2))
坐标是一个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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.