Many customers confuse expanding a cell with flattening it. This confusion leads to using the incorrect Calibre DESIGNrev command "$L flatten cell" to manipulate their design instead of "$L expand cell".
Expanding a cell with the " $L expand cell" command flattens the references of the specified cell by bringing all geometries in the cell reference to the level of the parent cells, keeping any underlying hierarchy within the cell intact. Hence, the cell definition itself is left intact.
# Before:
# topcell -> a -> b -> c -> d
# topcell -> c -> d
set inlayout [layout create "input.oas" -dt_expand -preservePaths -preserveTextAttributes]
$inlayout expand cell b
$inlayout oasisout out.oas
# After:
# topcell -> a -> c -> d
# topcell -> c -> d
# b -> c -> d
On the other hand, flattening a cell with the " $L flatten cell" flattens all levels of hierarchy of the specified cell across all of its instances to the level of the parent cells, such that the cell and its underlying hierarchy are replaced by a flattened view of the shapes. Hence this impacts the cell definition, and all references to the cell.
# Before:
# topcell -> a -> b -> c -> d
# topcell -> b -> c -> d
# topcell -> c -> d
set lay [layout create "abcd.gds" -dt_expand -preservePaths -preserveTextAttributes]
$lay flatten cell b
$lay gdsout out.gds
# After:
# topcell -> a -> b
# topcell -> b
# topcell -> c -> d