LayoutScript in Ruby

LayoutScript for Ruby is an alternative scripting interface to build-in C++ Macros having the same Application Programming Interface (API). It is a regular extension module of Ruby for pure scripting without any graphical output and runs independent to the LayoutEditor application. It is build as an easy to use scripting feature for all kind of designs and can be use with all other extension modules Ruby offers. You can try and run LayoutScript without a license key. To use the export to some file formats a full version of the LayoutEditor is required in the case your design exceeds a certain size.

If you need scripting to adjust the user interface with new menu entry, create parametric cells from the schematic or callback macros after changing device parameter, please use LayoutEditor C++ Macros.

Getting Started

Using LayoutScript for Ruby is very simple. You can start a ruby script from the integrated TextEditor by pressing the execute button. No setup required, a ruby installation is shipped within most LayoutEditor installations. In the script the line "require 'LayoutScript'" will load the module and the line "include LayoutScript" will enable to use any LayoutScript command without a prefix. The Application Programming Interface (API) is identical to the LayoutEditor. All names are adjusted to the ruby naming convention. That means that all class names start with a capital letter and all methods are named with a separating _ instead of the use of CamelCase.The LayoutScript module is independent of any open layout window. So please don't forget to save the result in the script. Afterwards the created file can be loaded in the LayoutEditor.

Examples

# load the module
require 'LayoutScript'
# remove the need of the prefix
include LayoutScript

#create a new layout object
l=Project.new_layout()

Layers.num(6).name="new text"

c=l.drawing.currentCell
c.cellName="test-cell-ruby"

c.add_box(0,0,5000,7000,5)
c.add_rounded_box(10000,0,5000,7000,500,5)
c.add_chamfered_box(20000,0,5000,7000,500,5)
c.add_circle_box(Point.new(0,10000),Point.new(5000,17000),5)
c.add_ellipse(5,Point.new(12500,15000),2500,3500)
c.add_polygon_arc(Point.new(22500,15000),2500,3500,0,340,5)
e=c.add_text(5,Point.new(25,25000),Layers.num(6).name)
e.set_width(1000)
l.drawing.save_file("/home/user/testout.gds")

puts("Ruby script completed")

In this example the line require 'LayoutScript' will load the LayoutScript module for Ruby. The includes line remove the requirement of any prefix on the LayoutScript module. With the line l=Project.new_layout() a new instance of the LayoutEditor is created.

require 'LayoutScript'
include LayoutScript

l=Project.new_layout()

c=l.drawing.currentCell
c.cellName="randomCircleArray"

sizeX=10000 #array width
sizeY=10000 #array height
diameter=100 #circle diameter
count=2000 #number circles
layer =11  #layer for circles
space=50 #minimum circle to circle distance

ds=diameter+space;

for i in 1..count
 try=0
 found=false
 while (found == false) do
    try += 1
    x=Random.rand(sizeX)
    y=Random.rand(sizeY)
    p=Point.new(x,y);
    e=c.nearest_element(p)
    if e==nil
       found=true
    else 
       p2=Point.new()
       radius=PointerInt.new()
       # to assign radius use
       #radius.assign(34)
       # to output radius use
       #puts radius.value()
       if e.thisElement.is_circle(p2,radius)
           if p2.x()>x+ds
               found=true
           elsif p2.x()<x-ds
               found=true
           elsif p2.y()<y-ds
               found=true
           elsif p2.y()>y+ds
               found=true
           end
       end
    end

    if try>1000
       return 1
    end
 end
 c.add_circle(layer,p,diameter/2)

end

# save to your home folder
l.drawing.save_file("#{Dir.home}/testout.gds")
#l.drawing.save_file("/Users/apple/testout.gds")

puts "circle array completed" 

These example and many further ruby script using LayoutScript are including in any LayoutEditor package under macros/examples. These examples can be open with the integrated TextEditor under Utilities/LayoutEditor/Open Example Macro.

Platform Notes

LayoutScript for Ruby is available for Windows, Linux and Mac. It is included in the Windows packages, in all Linux packages and in the package for Mac OS systems. LayoutScript is not included in the Windows XP package and the package for older Mac Systems. On Linux it is recommended to use the package for your distribution. The general Linux package also includes it, but it may interfere with the installed ruby version. To use LayoutScript from outside the LayoutEditor set the environment variables PATH, LD_LIBRARY_PATH, RUBYLIB, RUBYOPT to the correct values before starting ruby. OpenAccess Script cannot be started from outside the LayoutEditor.