Page tree
Skip to end of metadata
Go to start of metadata

The main object in the layout is a DrawingObject. Due to the way the collection works vast efficiency differences can be seen when accessing it in different ways. Consider the following two code examples (the second one runs 10x faster).

 

' Code Module
' Slow code
Sub Main
        Dim lay As Layout
        Dim i As Integer
        Dim j As Integer
        Dim x As Double
        Dim y As Double

        Set lay = Project.Schematics("Schematic 1").Layout
        x = 0
        y = 0
        For i = 1 To 1000
                y = 0
                For j = 1 To 100
                        lay.DrawingObjects.AddRectangle(x, y, 10e-6, 10e-6) 'this is getting DrawingObjects from lay each loop iterations
                        y = y + 10e-6
                Next j
                x = x + 10e-6
        Next i
End Sub
' Code Module
' Fast code - add shapes directly to the drawing objects collection
Sub Main
        Dim lay As Layout
        Dim drawObjs As DrawingObjects
        Dim i As Integer
        Dim j As Integer
        Dim x As Double
        Dim y As Double

        Set lay = Project.Schematics("Schematic 1").Layout
        ' Get direct reference to drawObjs collection.
        Set drawObjs = lay.DrawingObjects   ' this get DrawingObject only once
        x = 0
        y = 0
        For i = 1 To 1000
                y = 0
                For j = 1 To 100
                        ' Add directly to drawObjs collection holding reference
                        drawObjs.AddRectangle(x, y, 10e-6, 10e-6)
                        y = y + 10e-6
                Next j
                x = x + 10e-6
        Next i
End Sub