File io Rhino:并非所有参数都在字符串格式化期间转换

File io Rhino:并非所有参数都在字符串格式化期间转换,file-io,typeerror,rhino,File Io,Typeerror,Rhino,我试图使用Rhino Python执行代码,但遇到以下TypeError问题: 消息:并非所有参数都在字符串格式化期间转换 我编写的代码旨在从文件“newpoints.csv”中读取点坐标,并将其用作Rhino Python的“AddLine”函数的参数 #!/usr/bin/env python import rhinoscriptsyntax as rs file = open("C:\\Users\\Seshane Mahlo\\Documents\\MSc Thesis\\newpoi

我试图使用Rhino Python执行代码,但遇到以下TypeError问题:

消息:并非所有参数都在字符串格式化期间转换

我编写的代码旨在从文件“newpoints.csv”中读取点坐标,并将其用作Rhino Python的“AddLine”函数的参数

#!/usr/bin/env python
import rhinoscriptsyntax as rs

file = open("C:\\Users\\Seshane Mahlo\\Documents\\MSc Thesis\\newpoints.csv", "r")
lines = file.readlines()
file.close()

ab = len(lines)
seq = range(0, ab-1, 2)
coordinates = []
startvals = []
stopvals = []

for line in lines:
    coords = line.split(',')
    xcoord = float(coords[0])
    ycoord = float(coords[1])
    point = (xcoord, ycoord)
    coordinates.append(point)

starts = range(0, ab-2, 2)
ends = range(1, ab+1, 2)

for i,j in zip(starts, ends):
   strt = coordinates[i]
   stp = coordinates[j]
   rs.AddLine(start=strt,end=stp)

我认为您的代码中有一个小错误:

starts = range(0, ab-2, 2)
ends = range(1, ab-1, 2)
应该是哪一个

starts = range(0, ab-1, 2)
ends = range(1, ab, 2)
因为从range函数得到的最后一个元素比stop参数小一个

但导致错误的原因是您试图添加一条线,该线由两个使用2元组(x,y)的3d点组成

要修复此更改,请执行以下操作:

point = (xcoord, ycoord)


或任何您想要的z坐标。

如果可以,请为错误消息提供更多上下文。根据给出的信息,不清楚您的代码在何处抛出此类型错误。@GGordonWorleyIII此错误似乎是由第27行回溯触发的:第348行,在强制点“C:\Users\Seshane Mahlo\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython(814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\utility.py”第310行,在“C:\Users\Seshane-Mahlo\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython(814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\curve.py”第27行,“C:\Users\Seshane-Mahlo\AppData\Roaming\McNeel\Rhinoceros\5.0\scripts\drawlines.py”
point = (xcoord, ycoord, 0)