You’re very close… a few comments:

```
cubit.cmd('merge all')
cubit.cmd('imprint all')
```

99.9% of the time, you want to `imprint all`

first, and then `merge all`

second

```
cubit.cmd('merge all')
cubit.cmd('imprint all')
#make set assignments
cubit.cmd('block 1 vol 1')
cubit.cmd('block 2 vol 3')
cubit.cmd('block 3 vol 2')
cubit.cmd('webcut volume in block 1 2 with plane xplane offset 2995')
cubit.cmd('webcut volume in block 1 2 with plane yplane offset 2995')
cubit.cmd('webcut volume in block 2 with plane zplane offset -1800')
```

The point of `imprint`

and `merge`

in this context is to connect/reconnect disconnected volumes to enable a contiguous mesh. Doing `imprint/merge`

and then webcutting (partitioning) defeats the purpose.

So you’ll want to reorganize to this:

```
# Make set assignments
cubit.cmd('block 1 vol 1')
cubit.cmd('block 2 vol 3')
cubit.cmd('block 3 vol 2')
# Partition for meshability
cubit.cmd('webcut volume in block 1 2 with plane xplane offset 2995')
cubit.cmd('webcut volume in block 1 2 with plane yplane offset 2995')
cubit.cmd('webcut volume in block 2 with plane zplane offset -1800')
# Ensure contiguous mesh
cubit.cmd('imprint all')
cubit.cmd('merge all')
```

Looking at the geometry *immediately* before the `imprint all`

command, I find it helpful to visualize vertices with `vertex vis on`

. Essentially, your earlier webcut of the green and yellow volumes with the magenta surface:

Results in some modification to some of the bounding curves – visualized here as red vertices:

Those vertices are indicators that those curves are “split” – meaning that the topology of the volume has changed and may not be recognizable to Cubit as meshable with the polyhedron scheme. However, assuming that it’s not otherwise critical to the simulation that we *exactly* maintain the topology (e.g., you’re not applying a boundary condition *only* to one half of the now-split curve) we can tell Cubit to ignore those vertices in the topology of those volumes, treating the two split curves as a single *composite* curve:

```
cubit.cmd('composite create curve all angle 1')
```

Note that we want to do this *before* we `imprint`

so that the topology won’t be accidentally “frozen” into merged entities:

```
cubit.cmd('composite create curve all angle 1')
cubit.cmd('imprint all')
cubit.cmd('merge all')
```

I also reorganized your meshing a bit:

```
# Assign mesh schemes
cubit.cmd('volume all scheme auto')
cubit.cmd('vol in block 1 scheme tetprimitive')
cubit.cmd('vol 3 5 8 9 scheme polyhedron')
# Assign mesh sizes
cubit.cmd('vol in block 1 size '+str(elementsize1))
cubit.cmd('vol in block 2 size '+str(elementsize2))
cubit.cmd('vol in block 3 size '+str(elementsize3))
# Mesh volumes
cubit.cmd('mesh vol all with has_scheme "polyhedron"')
cubit.cmd('mesh vol all with has_scheme "tetprimitive"')
cubit.cmd('mesh vol all except with is_meshed')
```

You might find this documentation page useful to understand the `with has_scheme "polyhedron"`

and `except with is_meshed`

commands:

https://coreform.com/cubit_help/cubithelp.htm#t=environment_control%2Fentity_selection_and_filtering%2Fextended_entity_specification.htm

So the final combined script is:

```
#!python
elementsize1 = 80
elementsize2 = 80
elementsize3 = 80
cubit.cmd('reset')
cubit.cmd('sphere radius 1200.0')
cubit.cmd('volume 1 move x 2995 y 2995.0')
cubit.cmd('webcut vol 1 with zplane')
cubit.cmd('delete vol 1')
#volume 3
cubit.cmd('vol 2 copy')
cubit.cmd('brick x 7000 y 7000 z 5000')
cubit.cmd('volume 4 move x 3500 y 3500 z -2500') # origin 0, 0, 0 [0, -5000]
cubit.cmd('volume 4 move x -500 y -500') # [-500 6500]
cubit.cmd('subtract vol 3 from vol 4')
cubit.cmd('undo group begin')
cubit.cmd('compress')
cubit.cmd('import "topo_coarse.cub" ')
cubit.cmd('import "layer3_coarse.cub" ')
cubit.cmd('webcut vol 1 2 tool body 3')
cubit.cmd('delete vol 5 6')
cubit.cmd('delete body 3')
cubit.cmd('webcut vol 2 tool body 4')
cubit.cmd('delete body 4')
cubit.cmd('compress')
cubit.cmd('sideset 1 surface 2 4')
# avoids assigning empty blocks
cubit.cmd('set duplicate block elements on')
# Make set assignments
cubit.cmd('block 1 vol 1')
cubit.cmd('block 2 vol 3')
cubit.cmd('block 3 vol 2')
# Partition for meshability
cubit.cmd('webcut volume in block 1 2 with plane xplane offset 2995')
cubit.cmd('webcut volume in block 1 2 with plane yplane offset 2995')
cubit.cmd('webcut volume in block 2 with plane zplane offset -1800')
# Virtual geometry cleanup
cubit.cmd('composite create curve all angle 1')
# Ensure contiguous mesh
cubit.cmd('imprint all')
cubit.cmd('merge all')
# Assign mesh schemes
cubit.cmd( 'volume all scheme auto' )
cubit.cmd('vol in block 1 scheme tetprimitive')
cubit.cmd('vol 3 5 8 9 scheme polyhedron')
# Assign mesh sizes
cubit.cmd('vol in block 1 size '+str(elementsize1))
cubit.cmd('vol in block 2 size '+str(elementsize2))
cubit.cmd('vol in block 3 size '+str(elementsize3))
# Mesh the volumes
cubit.cmd('mesh vol all with has_scheme "polyhedron"')
cubit.cmd('mesh vol all with has_scheme "tetprimitive"')
cubit.cmd('mesh vol all except with is_meshed')
# View the mesh
cubit.cmd( "draw block all" )
```