2013-06-27 20 views
1

我試圖用犀牛Python來執行代碼和我有以下類型錯誤的一些問題:犀牛:不是所有的參數轉換期間字符串格式化

Message: not all arguments converted during string formatting

我寫的意思的代碼讀取點座標從文件「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) 
+0

如果可以,請爲錯誤消息提供更多上下文。目前還不清楚你的代碼是從給定的信息中拋出這個TypeError的。 –

+0

@GordonWorleyIII錯誤似乎是由第27行跟蹤引起的: 第348行,在coerce3dpoint中,「C:\ Users \ Seshane Mahlo \ AppData \ Roaming \ McNeel \ Rhinoceros \ 5.0 \ Plug-ins \ IronPython(814d908a-e25c- 493d-97e9-ee3861957f49)\ settings \ lib \ rhinoscript \ utility.py「 line 310,in AddLine,」C:\ Users \ Seshane Mahlo \ AppData \ Roaming \ McNeel \ Rhinoceros \ 5.0 \ Plug-ins \ IronPython(814d908a -e25c-493d-97e9-ee3861957f49)\ settings \ lib \ rhinoscript \ curve.py「 line 27,in ,」C:\ Users \ Seshane Mahlo \ AppData \ Roaming \ McNeel \ Rhinoceros \ 5.0 \ scripts \ drawlines。 PY」 –

回答

0

我認爲這是在你的代碼的一個小錯誤的位置:

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

這應該是

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

,因爲你從範圍功能得到最後一個元素是一個小於停止參數。

但是是什麼原因造成的錯誤是,您要添加一條線,它是由使用2元組(X,Y)

爲了解決這個問題改變兩個3D點:

point = (xcoord, ycoord) 

point = (xcoord, ycoord, 0) 

或任何你想你的z座標是。

相關問題