Google Translate says: Is it possible to replace these two components with a GH Python component?
The simple way would be to Flatten the output from the Entwine
component. (simlar to how you have applied Simplify. Or, you can use the Flatten
component, to achieve the result on the last panel.
HTH
~ ~ ~ ~ ~ ~ ~ ~
Kaushik LS
Chennai, IN
Мне не нужно сгладить вывод. Мне нужен указанный результат (конечный список).
Since the input are only numbers, I would prefer this method.
HTH
# Make sure, the input access type is set to TreeAccess
from ghpythonlib import treehelpers
input_list = treehelpers.tree_to_list(x)
output_list = []
for outer_index in range(len(input_list)):
for inner_index in range(len(input_list[outer_index])):
element = input_list[outer_index][inner_index]
if element != None:
output_list.append(element)
a = sorted(output_list)
Or, if you don’t want to use ghpythonlib moduile,
# Make sure, the input access type is set to TreeAccess
input_list = x
output_list = []
for branch_index in range(input_list.BranchCount):
for item_index in range(len(input_list.Branch(branch_index))):
element = input_list.Branch(branch_index)[item_index]
if element != None:
print element
output_list.append(element)
a = sorted(output_list)
Это работает. Спасибо.
Можно ли мне обращаться к Вам по этому поводу?
Олег,
Россия
This works more like the Combine Data component.
Order is preserved if inputs are not in ascending order. The output could be sorted if desired. You could put conditions on which values to keep (max, min, etc…).
out_list = [None] * max([len(branch) for branch in x.Branches])
for branch_idx in range(x.BranchCount):
for item_idx in range(len(x.Branch(branch_idx))):
item = x.Branch(branch_idx)[item_idx]
if (item is not None):
out_list[item_idx] = item
a = out_list
-Kevin
Спасибо и Вам за ответ.
Я новичок. Как мне понимать этот код?
Олег
This is the definition I have used:
ghpython_combine_data.gh (12.5 KB)
This is the code and output from the GhPython Script component:
I added some comments and print statements so you can follow the execution.
Line #2 uses list comprehension to create a list filled with None items that has the same length as the longest branch in the input DataTree :
out_list = [None] * max([len(branch) for branch in x.Branches])
This simplified code is equivalent to:
branch_lengths = []
for branch in x.Branches:
branch_lengths.append(len(branch))
max_length = max(branch_lengths)
out_list = [None] * max_length
The rest of the code is pretty straightforward.
-Kevin
Спасибо. Код работает.
Но у меня в другом дереве данных содержатся Boxes.
А компонент GH Python делает из них Сlosed Breps.
Можно ли достичь того, чтобы он выводил Boxes?
Олег
Right-click on the GhPython component X input and select Type hint → Box
If you hover the mouse above the input, it will show its Access Type and Type Hint.
-Kevin
Мне нужно, чтобы путь был {1}.
Я поискал, но не нашёл, как этого достичь.
Не подскажете ли мне и на этот раз?
-Oleg
I don’t know why the output from the Combine Data component is at path {1}.
Modified code in GhPython component to output at path {1} also.
ghpython_combine_data_re.gh (15.6 KB)
Edit: Alternate method that works like Path Mapper component.
File includes both versions of script:
ghpython_combine_data_re2.gh (14.6 KB)
-Kevin
Спаcибо Kevin за помощь.
Пытаюсь разобрать этот код, пишу свои коментарии в каждой его строке. Хочу понять, как правильно читать код.
-Oleg
Привет, Kevin.
Это у тебя консоль Grasshopper Python Script Editor?
Я не вижу там настройки цвета фона консоли и цвета текста.
-Oleg
Yes, this is the Grasshopper Python Script Editor on MacOS.
-Kevin
Жаль, что у меня Windows, а то бы я настроил подобные цвета.