Support Forum

How to extract the center of polygons by a macro?

User
LayoutEditorFull
Saturday 23rd June 2018
I have a few polygons on layer 0 of my design, how can I extract its properties (length, width, and center coordinates) of each polygon with a macro?
Jürgen
LayoutEditorFull
Saturday 23rd June 2018
Please have a look at this macro: ```cpp #!/usr/bin/layout #name=polygon size #help=read polygon size on layer int main() { int myLayer=1; debug.clear(); // loop over all elements in the current cell elementList *l=layout->drawing->currentCell->firstElement; int count=0; while (l!=NULL) { if (l->thisElement!=NULL) { if ( l->thisElement->layerNum==myLayer) if ( l->thisElement->isPolygon() ){ // all polygons on layer 'myLayer' count++; debug("polygon: "+count); // center can be calulated from its boiunding box: point min=l->thisElement->minimum(); debug("minmum"); debug(min); point max=l->thisElement->maximum(); debug("maxmum"); debug(max); // getting the complete list of points of the polygon pointArray points=l->thisElement->getPoints(); // further properties can be analysed method of the class pointArray } } l=l->nextElement; } debug.show(); } ```
Jim
LayoutEditorFull
Thursday 5th July 2018
Hi Jürgen, Per your suggestion, I used the center of gravity method in the pointArray class to determine the midpoint of each polygon: pointArray points=l->thisElement->getPoints(); // getting the complete list of points of the polygon point centerPoint=points.centerOfGavity(); // the word GRAVITY is missing the R debug(centerPoint); Is it possible to display the centerPoint in User Units instead of Database Units?
Jürgen
LayoutEditorFull
Friday 6th July 2018
A multiplication with *layout->drawing->userunits* converts Database Units to User Units. So a *debug* statement in User Units can be achieved with: ```c++ debug(centerPoint.x()*layout->drawing->userunits," / ",centerPoint.y()*layout->drawing->userunits); ```