Incorrect/mismatched input type

unhandled
(Esolomon1221) #1

I’m confused as to why the input seems to be a collection but shows up in python as a single value. Python script and GH definition shown below.

import rhinoscriptsyntax as rs
import csv

typeMxx = 0; typeMyy = 1; typeTorsion = 2; typeMtot = 3
mxxFile = 'C:\Documents\LaGuajiraConstruccion\data\mxx.csv'
myyFile = 'C:\Documents\LaGuajiraConstruccion\data\mxx.csv'
torsionFile = 'C:\Documents\LaGuajiraConstruccion\data\torsion.csv'
mtotFile = 'C:\Documents\LaGuajiraConstruccion\data\mtot.csv'

def writeData(type,strength,location):
    fName = None
    if type == typeMxx:
        fName = mxxFile
    elif type == typeMyy:
        fName = myyFile
    elif type == typeTorsion:
        fName = torsionFile
    elif type == typeMtot:
        fName = mtotFile
    
    with open(fName,'w') as f:
        writer = csv.writer(f, delimiter=',')
        for i in len(strength):
            writer.writerow([location[i],strength[i]])

if __name__ == "__main__":
    print(strength)
    print(location)
    writeData(type,strength,location)

Generated error:

Runtime error (TypeErrorException): iteration over non-sequence of type int

Traceback:
  line 33, in writeData, "<string>"
  line 39, in script
(Lando Schumpich) #2

Did you set your input to list access?
You can right-click the input and choose list or tree access

(Esolomon1221) #3

list access gives the first element. tree access gives some error when using iteration:

Runtime error (ArgumentTypeException): __getitem__() takes exactly 2 arguments (1 given)
(Lando Schumpich) #4

Sorry I totally forgot about this topic
Since you are inputting datatrees I assume the structure of those is important to you.

Easiest way to show you how to do it would be given your gh file, if you can’t share it I can write up a mock up script after work

(Tim Stark) #5

Just guessing without testing. Shouldn‘t it be:
For i in range(len(strength)): ?