the fair gds editor MacroSchematicCreation
Please Sign in

schematic generated by a macro

Generation of a Schematic by a Macro

Macros are not limited on the modification on layouts. Maco can be use in the Schematic Editor as well. The macro presented on this page will create a schematic with an array of transistors and resistors and also wire it. The resulting schematic will be used for a schematic driven layout.

Download: schematicGeneration.layout

   1 #!/usr/bin/layout
   2 #name=schematic generation
   3 #help=generates a schematic by a macro
   4 
   5 
   6 int row(int num){
   7 return num/3;
   8 }
   9 
  10 int col(int num){
  11 return num % 3;
  12 
  13 }
  14 
  15 int main(){
  16 // generate schematic
  17 component *c=components::findComponent("BC107","PCB");
  18 if (c==NULL) return 2; // component not found
  19 
  20 pointArray emitter;   // to save emitter position for later use
  21 
  22 // place transistor
  23 for (int i=0;i<9;++i){
  24         point p;
  25         p.set(col(i)*100,-row(i)*200);
  26         strans tr;
  27        sElement *sel=schematic->drawing->currentSheet->addPlacement(c,p,tr);
  28        string dname=schematic->drawing->currentSheet->getUnusedDevicename(c->prefix);
  29        sel->addParameter("devicename",dname);
  30         point  pEmitter=sel->getPortPos("port3");
  31        emitter.attachPoint(pEmitter);
  32 }
  33 
  34 //place resistor
  35 c=components::findComponent("R","PCB");
  36 if (c==NULL) return 2; // component not found
  37 for (int i=0;i<9;++i){
  38         point p;
  39         p.set(col(i)*100+20,-row(i)*200-80);
  40         strans tr;
  41        tr.rotate(90);
  42        sElement *sel=schematic->drawing->currentSheet->addPlacement(c,p,tr);
  43        string dname=schematic->drawing->currentSheet->getUnusedDevicename(c->prefix);
  44        sel->addParameter("devicename",dname);
  45 
  46        // resister connection to ground
  47        point  pa=sel->getPortPos("pin1");
  48        schematic->drawing->currentSheet->addGround(pa);
  49 
  50        // resister to emitter conection
  51        pointArray emitterToR;
  52        emitterToR.attachPoint(emitter.point(i));
  53        pa=sel->getPortPos("pin2");
  54        emitterToR.attach(pa.x(),emitter.point(i).y());
  55        emitterToR.attachPoint(pa);
  56        schematic->drawing->currentSheet->addWire(emitterToR);
  57 }
  58 
  59 // update view and netlist
  60 schematic->drawing->updateCurrentNetlist();
  61 schematic->drawing->scaleFull();
  62 
  63 // generate layout
  64 for (int i=0;i<9;++i){
  65         point p;
  66         p.set(col(i)*9000000,-row(i)*9000000);
  67         strans tr;
  68         layout->netlistTool->placeDevice("QN"+(i+1),p,tr);
  69         p.set(col(i)*9000000+3800000,-row(i)*9000000+3000000);
  70         tr.rotate(270);
  71         layout->netlistTool->placeDevice("R"+(i+1),p,tr);
  72 }
  73 layout->drawing->scaleFull();
  74 
  75 // autorouter can be used to generate the connections
  76 
  77 }

See also

* IntroductionSchematicDrivenLayout * CategoryMacro * SchematicEditor


CategoryMacro


MacroSchematicCreation (last edited 2015-10-29 10:43:54 by JürgenThies)