Enable Python support and load DesignScript library
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
from operator import itemgetter
The inputs to this node will be stored as a list in the IN variables.
allpts = IN[0]
otherpts = IN[1]
Place your code below this line
firstpt = allpts[0]
visitedpts = [firstpt]
currentpts = visitedpts[-1]
del otherpts[0]
cur_other_dis =
target_list_values =
l = len(otherpts)
#I want to repeat the following work!! but I don’t know how to write
for i in range(l):
dis = round(Geometry.DistanceTo(currentpts, otherpts[i]))
cur_other_dis.append(dis)
target_list_index = [i for i, x in enumerate(cur_other_dis) if x == 350]
target_list_len = len(target_list_index)
if target_list_len == 1:
target_list_values.append(otherpts[0])
target_list_value = target_list_values[0]
elif target_list_len == 2:
for z in target_list_index:
target_list_values.append(otherpts[z])
target_list_values = sorted(target_list_values)
target_list_value = target_list_values[0]
So you can get the help you need a little faster, please can you explain the problem you are facing ie. What you are trying to do, and what issues you are experiencing and also format your code with the </> button so it is a little more legible.
Thank you for teaching me !!!
I don’t know why the error happens
Thank you in advance!!
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
from operator import itemgetter
# The inputs to this node will be stored as a list in the IN variables.
allpts = IN[0]
otherpts = IN[1]
# Place your code below this line
firstpt = allpts[0]
visitedpts = [firstpt]
currentpts = visitedpts[-1]
del otherpts[0]
cur_other_dis = []
target_list_values = []
l = len(otherpts)
dis = []
for w in range(9):
for i in range(l):
dis = round(Geometry.DistanceTo(currentpts, otherpts[i]))
cur_other_dis.append(dis)
target_list_index = [i for i, x in enumerate(cur_other_dis) if x == 350]
target_list_len = len(target_list_index)
#候補が一個の場合
if target_list_len == 2:
for z in target_list_index:
target_list_values.append(otherpts[z])
target_list_values = sorted(target_list_values)
target_list_value = target_list_values[0]
visitedpts.append(target_list_value)
otherpts.Remove(target_list_value)
elif target_list_len == 1:
target_list_values.append(otherpts[0])
target_list_value = target_list_values[0]
currentpts = visitedpts[-1]
cur_other_dis = []
target_list_values = []
target_list_index = []
l = len(otherpts)
OUT = [firstpt, visitedpts, currentpts, otherpts, target_list_value, target_list_values, target_list_len, cur_other_dis, target_list_len]
You have mixed tabs and spaces when indenting the if statement which has confused the interpreter. Although you can use either in Python, its best to be consistent. PEP-8 style is 4 spaces
Below is the code with the tabs replaced by four spaces. It throws different errors now about target_list_value, but I don’t know what point data you want to feed it.
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
from operator import itemgetter
# The inputs to this node will be stored as a list in the IN variables.
allpts = IN[0]
otherpts = IN[1]
# Place your code below this line
firstpt = allpts[0]
visitedpts = [firstpt]
currentpts = visitedpts[-1]
del otherpts[0]
cur_other_dis = []
target_list_values = []
l = len(otherpts)
dis = []
for w in range(9):
for i in range(l):
dis = round(Geometry.DistanceTo(currentpts, otherpts[i]))
cur_other_dis.append(dis)
target_list_index = [i for i, x in enumerate(cur_other_dis) if x == 350]
target_list_len = len(target_list_index)
#候補が一個の場合
if target_list_len == 2:
for z in target_list_index:
target_list_values.append(otherpts[z])
target_list_values = sorted(target_list_values)
target_list_value = target_list_values[0]
visitedpts.append(target_list_value)
otherpts.Remove(target_list_value)
elif target_list_len == 1:
target_list_values.append(otherpts[0])
target_list_value = target_list_values[0]
currentpts = visitedpts[-1]
cur_other_dis = []
target_list_values = []
target_list_index = []
l = len(otherpts)
OUT = [firstpt, visitedpts, currentpts, otherpts, target_list_value, target_list_values, target_list_len, cur_other_dis, target_list_len]