Electric has the Bean Shell built into it. This enables you to load custom Java code that adds functionality to Electric. The Bean Shell is not part of the default Electric distribution. You must add it as a "plug in" (see Section 1-5 for more on plug-ins).

To run a script, use the Run Java Bean Shell Script... command (in menu Tools / Languages).

You can attach a script to the Tools / Languages menu by using the Manage Java Bean Shell Scripts... command. Scripts can have mnemonic letters assigned to them (see Section 1-9 for more on mnemonics). |

Here are some example scripts in the Java Bean Shell. For more information about accessing the internals of Electric, read the Javadoc in the source code.

`import com.sun.electric.database.hierarchy.Cell; import com.sun.electric.database.topology.NodeInst; import com.sun.electric.tool.Job; import java.util.Iterator; // get the current cell Cell lay = Job.getUserInterface().getCurrentCell(); // find all transistors for(Iterator it = c.getNodes(); it.hasNext(); ) { NodeInst ni = it.next(); if (ni.getFunction().isTransistor()) System.out.println("Found transistor: " + ni.describe(false)); } // find all exports that start with "A" for(Iterator it = lay.getPorts(); it.hasNext(); ) { com.sun.electric.database.hierarchy.Export e = (com.sun.electric.database.hierarchy.Export)it.next(); if (e.getName().toLowerCase().startsWith("a")) System.out.println("Found export: " + e.getName()); }`
| This example searches the current cell, printing all transistors and all exports that start with the letter "a". Notice that Electric's "Export" object must be a fully-qualified name, because the name "Export" is used for other reasons in the Bean Shell. This also applies to Electric's "EPoint" class.

`import com.sun.electric.database.hierarchy.Cell; import com.sun.electric.database.topology.NodeInst; import com.sun.electric.database.variable.EvalJavaBsh; import com.sun.electric.technology.PrimitiveNode; import com.sun.electric.technology.Technology; import java.awt.geom.Point2D; Cell newCell = Cell.makeInstance(Library.getCurrent(), "samp1{lay}"); Technology tech = Technology.findTechnology("mocmos"); PrimitiveNode trP = tech.findNodeProto("P-Transistor"); NodeInst tP = NodeInst.makeInstance(trP, new Point2D.Double(10, 10), trP.getDefWidth(), trP.getDefHeight(), newCell); EvalJavaBsh.displayCell(newCell);`
| This example creates a new cell, places a transistor in it, and displays the cell.

`import com.sun.electric.database.hierarchy.Cell; import com.sun.electric.database.geometry.Orientation; import com.sun.electric.database.topology.ArcInst; import com.sun.electric.database.topology.NodeInst; import com.sun.electric.technology.ArcProto; import com.sun.electric.technology.PrimitiveNode; import com.sun.electric.technology.Technology; import java.awt.geom.Point2D; // create the new cell Cell newCell = Cell.makeInstance(Library.getCurrent(), "samp2{lay}"); Technology tech = Technology.findTechnology("mocmos"); // place a rotated transistor PrimitiveNode trP = tech.findNodeProto("P-Transistor"); NodeInst tP = NodeInst.makeInstance(trP, new Point2D.Double(0, 20), trP.getDefWidth(), trP.getDefHeight(), newCell, Orientation.R, "T1"); // place a metal-Active contact PrimitiveNode coP = tech.findNodeProto("Metal-1-P-Active-Con"); NodeInst maP = NodeInst.makeInstance(coP, new Point2D.Double(8, 20), coP.getDefWidth(), coP.getDefHeight(), newCell); // wire the transistor to the contact ArcProto aP = tech.findArcProto("P-Active"); ArcInst.makeInstance(aP, tP.findPortInst("diff-bottom"), maP.findPortInst("metal-1-p-act")); // export the contact com.sun.electric.database.hierarchy.Export.newInstance(newCell, maP.findPortInst("metal-1-p-act"), "IN", PortCharacteristic.IN);`
| This example goes a bit further: it creates a rotated transistor and a contact, wires them together, and exports the contact. The transistor is named "T1."