Now that we know how to import a reference library from our Scripting How-To: How Can I Import an Artwork Cell Library for Use in my Design . Let's build on this by creating a new library with a new cell and adding some cell instances from the reference library into the newly created cell. The script code for this looks like the following:

 ' Code Module
Sub Main
        Dim cellLib As CellLibrary
        Dim libCell As Cell
        Dim x As Double, y As Double
        Dim i As Integer, j As Integer

        ' Import a reference library
        Project.CellLibraries.Import("MyRefLib", "C:\ReferenceLibs\CCADC.GDS", mwCLT_GDSII)

        ' Create a new cell library
        Set cellLib = Project.CellLibraries.Add("MyLib", mwCLT_GDSII)

        ' Add a new cell to the cell library
        Set libCell = cellLib.Cells.Add("MyCell")

        ' Add cells from our reference lib to the new cell
        x = 0
        y = 0
        For i = 1 To 10
                x = x + 100e-6
                y = 0
                For j = 1 To 10
                        y = y + 100e-6
                        libCell.Instances.Add("MyRefLib", "AND2", x, y)
                Next j
        Next i

        ' Open an editor on the cell we just created.
        libCell.EditCell

End Sub

 

We'll go through this code line by line and explain each step. The first part should look familiar from our description of importing a reference library: Scripting How-To: How Can I Import an Artwork Cell Library for Use in my Design :

      ' Import a reference library
        Project.CellLibraries.Import("MyRefLib", "C:\ReferenceLibs\CCADC.GDS", mwCLT_GDSII)

 

In this line we are importing the GDSII reference library located at "C:\ReferenceLibs\CCADC.GDS" into the project and giving it the name "MyRefLib". We'll use a cell from this library to start us off on the new cell. Since this is a reference library we'll probably want to create our cell in a different library so we don't disturb the reference library which others may be using in their designs.

The next step is to create a new library to hold our new cell.

     ' Create a new cell library
        Set cellLib = Project.CellLibraries.Add("MyLib", mwCLT_GDSII)

 

This creates a new GDSII cell library in the project called "MyLib". Well use this library to hold our new cells for this design project. Note here we retained a reference to the cell library in the variable 'cellLib' so we can use this to create a new cell in the cells collection of this library. This is done as follows:

      ' Add a new cell to the cell library
        Set libCell = cellLib.Cells.Add("MyCell")

 

Here we've use the Cells collection of the cell library to add a new empty cell called "MyCell". Note here again we keep a reference to the new cell in the variable 'libCell' so we can use this add the cell instances.

The next step is to populate this cell with some instances of a cell from our reference library. We do that in the a loop like this:

      ' Add cells from our reference lib to the new cell
        x = 0
        y = 0
        For i = 1 To 10
                x = x + 100e-6
                y = 0
                For j = 1 To 10
                        y = y + 100e-6
                        libCell.Instances.Add("MyRefLib", "AND2", x, y)
                Next j
        Next i

 

Here we create two variables x and y to represent the cell origin location and use these inside a double loop to loop over the rows and columns each time incrementing x by 100um in the outer loop to locate the column position and thin in the inner loop we increment the y by 100um to traverse up each column populating the rows.

Finally, so we can see the resulting cell we open the cell into an editor

   ' Open an editor on the cell we just created.
        libCell.EditCell

 

The resulting libary cell looks as follows:

Figure 1 New Library Cell with Cell Instances added from a Reference Library

These steps can be used to provide a quick head-start for standard designs which use cells from a cell library as a starting point. Once the reference cell library is imported you can easily create a new library with a new cell and populate it with cells from the reference library. Finally you can open the newly create cell in an editor ready for further layout.