Generating individual views off spaces

Hey All, I need a hand to point me in the right direction. I’ve created the .dyn script below where I am aiming to output a view of each MEP space but I am currently stuck. It runs the first space and names this correctly(ish, but it’s fine for a starter) but then stops with the tracebrack report on the right. I could do with integrating a loop that runs through each space then stops at the stops at the last but this is beyond me currently. Any pointers would be appreciated! Thanks, Lewis Capture