Arrays 从文件读取顶点位置时出现来自_pydata的混合器错误
我得到了错误Arrays 从文件读取顶点位置时出现来自_pydata的混合器错误,arrays,file,blender,Arrays,File,Blender,我得到了错误 Error: Array length mismatch (expected 3, got 13) TypeError: a float is required Traceback (most recent call last): File "\Test.py", line 393, in from_pydata File "C:\Program Files (x86)\Blender Foundation\Blender\2.68\2.68\scripts\modules\bpy
Error: Array length mismatch (expected 3, got 13)
TypeError: a float is required
Traceback (most recent call last):
File "\Test.py", line 393, in from_pydata
File "C:\Program Files (x86)\Blender Foundation\Blender\2.68\2.68\scripts\modules\bpy_types.py", line 393, in from_pydata
self.vertices.foreach_set("co", vertices_flat)
TypeError: couldn't access the py sequence
Error: Python script fail, look in the console for now...
代码如下:
filePath = "C:\\Users\\siba\\Desktop\\1x1x1.blb"
f = open(filePath)
line = f.readline()
while line:
if(line == "POSITION:\n"):
POS1 = f.readline().replace('\n','')
line = f.readline()
f.close()
coord1 = POS1
Verts = [coord1]
import bpy
profile_mesh = bpy.data.meshes.new("Base_Profile_Data")
profile_mesh.from_pydata(Verts, [], [])
profile_mesh.update()
profile_object = bpy.data.objects.new("Base_Profile", profile_mesh)
profile_object.data = profile_mesh
scene = bpy.context.scene
scene.objects.link(profile_object)
profile_object.select = True
这是1x1x1.blb:
POSITION:
0.5 0.5 0.5
只是暗中捅了一刀,因为我没有编写Blender脚本,我也懒得去查找文档,但我可以想象,
Verts
需要一个浮动列表,并且您提供了一个空格分隔的字符串,所以这可能会起作用:
coord1 = POS1.split(' ')
map(float, coord1)
Verts = coord1
这似乎不是一个与编程相关的问题?!?。。。。什么?Blender是一个python脚本程序。你能给我指出一条我可能违反的规则吗?我没有注意到脚本;请把它作为你问题的一部分,让它更明显。你可能没有违反规则;这些东西不是黑白的,而且类型错误通常通过铸造来解决
coord1=float(POS1)
可能会这样做。我把它放在海盗版上,因为它通常表现得很糟糕。不,仍然得到“需要浮点”:sIt的Python3,所以不确定map
是否仍然有效。但这个想法是正确的,可以尝试使用循环迭代数组,并将每个元素转换为float。如果您遇到错误,请指定具体位置-很难预测您已经进行了哪些修改。