the fair gds editor MacroExample6

Macro Example 6

This example shows the handling files from a macro.

Download: Sample6.layout

This examples as well as a LayoutScript version of it is also included in any LayoutEditor package in the folder macros/examples.

next example

   1 #!/usr/bin/layout
   2 #name=#6: File I/O
   3 #help=write all polygons of layer 23 in a file
   4 
   5 int  main() {
   6   file f;
   7 
   8   // add platform spezific path like "/home/username/filename" or "c:/my Files/filename.txt"
   9   string s="poly_on_23.txt";
  10   f.filename=s;
  11   bool b=false;
  12 
  13   //open for output
  14   f.open(b);
  15 
  16   s="";
  17   point p;
  18   string s1,s2,s3;
  19   int r;
  20   
  21   // loop over all cels
  22   cellList *cells=layout->drawing->firstCell;
  23     while (cells!=NULL){
  24     if (cells->thisCell!=NULL){
  25        elementList *l=cells->thisCell->firstElement;
  26 
  27        // loop over all elements
  28        while (l!=NULL) {
  29           if (l->thisElement!=NULL) {
  30              if (l->thisElement->layerNum==23){
  31                 if ( l->thisElement->isPolygon() ) {
  32                         pointArray pa=l->thisElement->getPoints();
  33                         int i;
  34                         s3.setNum(pa.size());
  35                         s+="Polygon ("+s3+"):";
  36                         for (i=0; i<pa.size(); i++){
  37                                 p=pa.point(i);
  38                                 s1.setNum(p.x());
  39                                 s2.setNum(p.y());
  40                                 s+="("+s1+","+s2+") ";
  41                                 }
  42                         s+="\n";
  43                         }
  44                 }}
  45           l=l->nextElement;
  46         }
  47       }
  48    cells=cells->nextCell;
  49   }
  50 
  51   // write string
  52   f.write(s);
  53 
  54   // close file
  55   f.close();
  56 }

See also


CategoryMacro


MacroExample6 (last edited 2017-05-07 08:28:17 by JurgenThies)