# How do I move parts along a belt?

A belt delays each part by its length over its speed and holds only so many parts. The script runs a 30 m belt at 1 and 2 metres a second.

```python
from nagasim import build as nb


def belt_run(speed):
    m = nb.Model(time_limit=600, time_unit="seconds")
    m.add_resource(name="Packer")
    parts = m.create(distribution=nb.Constant(value=10))
    # A 30 m belt; `spacing` is the least gap between parts on it, in the same length unit.
    belt = m.conveyor(length=30, speed=speed, spacing=1.0)
    parts >> belt >> m.process(resource_name="Packer", distribution=nb.Constant(value=4)) >> m.dispose()
    return m.run(seed=1)["conveyor_summary"].iloc[0]


for speed in (1.0, 2.0):
    row = belt_run(speed)
    print(f"belt at {speed} m/s: transit {row['Avg Transit Time']:.1f} s, "
          f"{row['Avg Occupancy']:.1f} parts on the belt on average")

```

Save it as `recipe-belt-transit.py` and run it with `python`. The script seeds itself, so the numbers below are the same on your machine.

```text
belt at 1.0 m/s: transit 30.0 s, 3.0 parts on the belt on average
belt at 2.0 m/s: transit 15.0 s, 1.5 parts on the belt on average

```

## How it works

1. `m.conveyor(length, speed, spacing)` moves a part from one end to the other in `length / speed`, and `spacing` is the gap between parts.
2. At 1 m/s a part takes 30 s, and at 2 m/s 15 s, so the belt holds 3 parts and then 1.5 on average.
3. The `conveyor_summary` frame also reports blocked time, so a full belt shows up there.

## Elements used

- Blocks: [CREATE](../../reference/blocks/create.md), [PROCESS](../../reference/blocks/process.md), [DISPOSE](../../reference/blocks/dispose.md), [CONVEYOR](../../reference/blocks/conveyor.md).
- Python: [`Model`](../../reference/api/Model.md).

Back to all [recipes](index.md).
