the fair gds editor BatchMacro

Batch Macro

This macro create a batch cell and fills it with the design as often it fits into a defined area.

Download: batch.layout

   1 #!/usr/bin/layout
   2 #name=batchgeneration
   3 #help=generates a batch by repeating structures
   4 
   5 
   6 int main(){
   7         layout->closeDesign(); // close, if a design is still open
   8         string fileName=layout->getOpenFilename();
   9         string resultName=fileName;
  10         string extension=fileName.mid(fileName.length()-4);
  11         if ((extension==".DXF")||(extension==".dxf")){
  12                 // setting correct units for a DXF file
  13                 string units= layout->getText("units","Units? (um,mm,nm)","mm");
  14                 layout->drawing->databaseunits=0.000000001;
  15                 if (units=="um")layout->drawing->userunits=0.001;
  16                 else if (units=="µm")layout->drawing->userunits=0.001;
  17                 else if (units=="mm")layout->drawing->userunits=0.000001;
  18                 else if (units=="nm")layout->drawing->userunits=1;
  19                 else {
  20                         layout->drawing->userunits=0.001;
  21                         layout->showMessage("???","unknow units, using µm");
  22                 }
  23                 resultName=fileName+"_batch"+".gds";
  24                 }
  25         else 
  26              resultName=fileName.left(fileName.length()-4)+"_batch.gds";
  27         //open file
  28         layout->drawing->openFile(fileName);
  29         layout->drawing->userunits=0.001;
  30         layout->filename=resultName;
  31         layout->drawing->currentCell->selectAll();
  32         // move minimum to origin
  33         point min,max;
  34         layout->drawing->currentCell->minimumSelect(&min);
  35         min.setX(-min.x());
  36         min.setY(-min.y());
  37         layout->drawing->currentCell->moveSelect(min);
  38         // calc maximal repeations
  39         layout->drawing->currentCell->maximumSelect(&max);
  40         int maxsize=100000000;
  41         int nx,ny;
  42         nx=maxsize/max.x();
  43         ny=maxsize/max.y();
  44         if ((ny==0)||(nx==0)){
  45                 // design to large
  46                 //cropping design
  47                 layout->drawing->deselectAll();
  48                 layout->drawing->point(0,0);
  49                 layout->drawing->point(maxsize,maxsize);
  50                 layout->drawing->activeLayer=200;
  51                 layout->drawing->box();
  52                 layout->drawing->selectActiveLayer();
  53                 layout->drawing->currentCell->cropWithSelection();
  54         } else {
  55                 //generating batch cell
  56                 string cellname=layout->drawing->currentCell->cellName;
  57                 layout->drawing->newCell();
  58                 layout->drawing->currentCell->cellName="batchCell";
  59                 // insert array
  60                 layout->drawing->point(0,0);
  61                 layout->drawing->point(max);
  62                 layout->drawing->cellrefarray( cellname,nx,ny);
  63                 // align array to center
  64                 layout->drawing->selectAll();
  65                 layout->drawing->point(0,0);
  66                 layout->drawing->point(maxsize,maxsize);
  67                 layout->drawing->alignCenterXY();
  68         }
  69         // add frame boxes
  70         layout->drawing->point(0,0);
  71         layout->drawing->point(maxsize,maxsize);
  72         layout->drawing->activeLayer=1;
  73         layout->drawing->box();
  74         layout->drawing->point(-10000,-10000);
  75         layout->drawing->point(maxsize+10000,maxsize+10000);
  76         layout->drawing->activeLayer=2;
  77         layout->drawing->box();
  78         // save to gds
  79         layout->save();
  80         layout->drawing->scaleFull();
  81 }

See also


CategoryMacro


BatchMacro (last edited 2010-12-26 19:45:51 by dslb-092-075-140-183)