# Slicing in a loop

Hi, I'm attempting to slice away pieces of a system to study the slice further, however my script does not behave as expected. I've seen some previous post regarding slicing in a loop over timesteps, however this is simply a loop over the grid to slice away each portion of it. Does ovito not like slicing in loops?

This code slices away squares of a NxN grid. When i print out (i+1)*lx etc and retrace the steps in graphical ovito i'm left with a nice slice of the system, however the ovito.io export_file call says there is no data to be exported.

```for i in range(grid[0]): #grid is a tuple of system dimension ex (3,3)
for j in range(grid[1]):
if bool_grid[i,j]: #is boo_grid is 1, we have an asperity
print('asperity at', i,j)
#lx ly is size of one square

# first outward slice X direction
pipeline.modifiers.append(SliceModifier(
distance = (i+1)*lx,
normal = (1.0, 0.0, 0.0)))

# first inward slice X direction
pipeline.modifiers.append(SliceModifier(
distance = (i)*lx,
normal = (1.0, 0.0, 0.0),
inverse = True))

# first outward slice Y direction
pipeline.modifiers.append(SliceModifier(
distance = (j+1)*ly,
normal = (0.0, 1.0, 0.0)))

# first outward slice Y direction
pipeline.modifiers.append(SliceModifier(
distance = (j)*ly,
normal = (0.0, 1.0, 0.0),
inverse = True))

export_file(pipeline, 'test_block_asperity{}'.format(asperity), 'lammps/data', atom_style = 'atomic')

del pipeline.modifiers
```

For context i'll add a couple of screenshots of the system and what i'm trying to achieve.

Thanks in advance for any help

Hi Anders,

I can't tell you exactly what is going wrong since I don't have the complete code, but I think this can be simplified by using an ExpressionSelectionModifier. This should work as expected:

```for i in range(grid[0]): #grid is a tuple of system dimension ex (3,3)
for j in range(grid[1]):
if bool_grid[i,j]: #is boo_grid is 1, we have an asperity
print('asperity at', i,j)
data = pipeline.compute()
expression = f"Position.X >= {i*lx} && Position.X < {(i+1)*lx} && Position.Y >= {j*ly} && Position.Y < {(j+1)*ly}"
data.apply(ExpressionSelectionModifier(expression = expression))
data.apply(InvertSelectionModifier())
data.apply(DeleteSelectedModifier())
export_file(data, f'test_block{i}{j}.data', 'lammps/data', atom_style = 'atomic')```

### 新的OVITO微信频道!New for our users in China: OVITO on WeChat

Official OVITO WeChat channel operated by Foshan Diesi Technology Co., Ltd.