User LayoutEditorFull Thursday 28th January 2021
Is there a way to view a list of cells in the hierarchy being currently viewed (or globally) with instance name, coordinates, scale, rotation, array size, array step, etc. and/or to export this to a text or csv file?
Jürgen LayoutEditorFull Thursday 28th January 2021
There is no native function doing this. You need to write a little macro doing this job. The macro may look like:
```cpp
#!/usr/bin/layout
#name=print cellrefs
#help=print cellrefs
int main(){
string result="";
elementList *el=layout->drawing->currentCell->firstElement;
// loop over all elements on the current cell
while (el!=NULL){
if (el->thisElement!=NULL)
if (el->thisElement->isCellref()) { // add element to result string if it is a cellref
result+="reference to "+el->thisElement->depend()->cellName+"\n";
string sx,sy;
sx.setNum(el->thisElement->getPoints().point(0).x());
sy.setNum(el->thisElement->getPoints().point(0).y());
result+="at "+sx+" / "+sy+"\n";
sx.setNum(el->thisElement->getTrans().getAngle(),3);
sy.setNum(el->thisElement->getTrans().getScale(),3);
result+="angle: "+sx+" with a scale of "+sy+"\n\n";
}
el=el->nextElement;
}
// display the results in the text editor
textEdit *te=project::getCentralTextEditor();
if (te->drawing->text()!="") {
te->newFile();
te->setFile(te->countFiles()-1);
}
te->setText(result);
te->drawing->title="List of Cellrefs";
te->drawing->setModifySaved();
}
```
User LayoutEditorFull Wednesday 3rd February 2021
Thanks. Really useful. Can see how you are looping through elements in the current cell and easy to modify so is space delimited table suitable for excel import. How would you suggest adding details of cells at a lower level in the current cell hierarchy to the list (i.e. cells in the cells just listed)?
Jürgen LayoutEditorFull Wednesday 3rd February 2021
The macro below will print the hierarchy structure of your current displayed cell. It is recursive, the function printCellHierarchy is calling itself until the lowest hierarchy level is reached.
```cpp
#!/usr/bin/layout
#name=print cellrefs
#help=print cellrefs
string result="";
void printCellHierarchy(cell *c,int level){
elementList *el=c->firstElement;
// loop over all elements in call "c"
while (el!=NULL){
if (el->thisElement!=NULL)
if (el->thisElement->isCellref()) { // add element to result string if it is a cellref
for (int i=0; i<level; ++i) result+= " ";
result+=el->thisElement->depend()->cellName+"\n";
// desent on referred cell
printCellHierarchy(el->thisElement->depend(),level+1);
}
el=el->nextElement;
}
}
int main(){
//display hierarchy of the current cell
printCellHierarchy(layout->drawing->currentCell,0);
// display the results in the text editor
textEdit *te=project::getCentralTextEditor();
if (te->drawing->text()!="") {
te->newFile();
te->setFile(te->countFiles()-1);
}
te->setText(result);
te->drawing->title="Hierarchy of the design";
te->drawing->setModifySaved();
}
```