Multiple Boxes

in this picture i wanna try to create one box and add to boxList and show all boxes on my screen. However ,in every timer cycle it creates one box and it makes it throw at boxList and update just the box position.it is not created multiple boxes through timer cycle.

how can i do that_?
makeBox.gh (5.5 KB)

This will fix it! Rename your output to boxes first.

import Rhino.Geometry as rg


class Agent:
    def __init__(self,p):
        self.pos = p
    
    def update(self):
        self.pos += rg.Vector3d(10, 10, 10)
    
    def get_box(self):
        sizex = rg.Interval(0, 10)
        sizey = rg.Interval(0, 10)
        sizez = rg.Interval(0, 10)
        plane = rg.Plane(self.pos, rg.Vector3d(0,0,1))
        return rg.Box(plane, sizex, sizey, sizez)
    
    def __copy__(self):
        return Agent(self.pos)


if __name__ == "__main__":

    if reset or "agents" not in globals():
        agents = []
        ag = Agent(rg.Point3d(0, 0, 0))
        agents.append(ag)
    else:
        ag = agents[-1].__copy__()
        ag.update()
        agents.append(ag)

    boxes = []  # Output
    if "agents" in globals():
        for ag in agents:
            boxes.append(ag.get_box())

The thing you got wrong is that your making the timer variable persistent - even though you don’t need it -, but your agent is only created at the first iteration, and after that only its position gets updated.
What you want to do instead is make a list that keeps track of the created agents persistent in globals().

2021-05-12 15-44-14.2021-05-12 15_45_13

1 Like

great!!!thank you so much…

1 Like

Why Python instead of standard components? And why a timer?

because i wanna explore capabilities of GhPython like processing.