Recognizing multiple partitions and sorting them by parameter ("SOFiSTiK_ShapeCode" / "Bar Length" / "Bar Diameter")

Here is my Dynamograph. My goal is that so this code is first able to recognize how many rebar partition I have in my drawing , and based on that information to make separate rebar lists with those partitions . Then next to sort those list with inserted parameter “SOFiSTiK_ShapeCode”.
What do I need to change so I dont get the ‘‘null’’ Watch node.
I added the code below

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

allRebars = IN[0]

# Collect unique partition values
unique_partitions = set()
for rebar in allRebars:
    partition = rebar.GetParameterValueByName("Partition")
    unique_partitions.add(partition)

# Create lists for each unique partition
partitioned_rebars = {partition: [] for partition in unique_partitions}

# Populate the lists
for rebar in allRebars:
    partition = rebar.GetParameterValueByName("Partition")
    partitioned_rebars[partition].append(rebar)

# Convert the dictionary to a list of lists for output
partitioned_rebars_lists = [partitioned_rebars[partition] for partition in unique_partitions]

# Assign your output to the OUT variable.
OUT = partitioned_rebars_lists

Try to flatten lists before ListSortByKey. Or add @@L2 in ListSortByKey. Can’t understand your task.

You’ll need to sort and group by key to keep a tiered structure. With each new parameter you want to sort by you’ll need to introduce a new list level to your sort/group nodes.

There are a ton of similar topics on the forum already that can give you examples.

1 Like