' New CamBam VBScript
' region creation

sub main

    '****** create 4 polylines ************************

    dim p1 as polyline = new polyline()    '2 concentric circles
    dim p2 as polyline = new polyline()    

    dim p3 as polyline = new polyline()    '2 rectangles
    dim p4 as polyline = new polyline()    

    p1.Add(15,0,0,0.577350269189625)
    p1.Add(-7.5,12.99,0,0.577350269189625)
    p1.Add(-7.5,-12.99,0,0.577350269189625)
    p1.closed = true

    p2.Add(30,0,0,0.577350269189625)
    p2.Add(-15,25.98,0,0.577350269189625)
    p2.Add(-15,-25.98,0,0.577350269189625)
    p2.closed = true

    p3.Add(26,52,0,0)
    p3.Add(46,52,0,0)
    p3.Add(46,61,0,0)
    p3.Add(26,61,0,0)
    p3.closed = true

    p4.Add(10,45,0,0)
    p4.Add(61,45,0,0)
    p4.Add(61,71,0,0)
    p4.Add(10,71,0,0)
    p4.closed = true

    doc.Add(p1)
    doc.Add(p2)
    doc.Add(p3)
    doc.Add(p4)

    View.RefreshView()

    '*********************************

    dim p_array(3) as polyline    ' an array of polylines (it must not have empty elements)

    p_array(0) = p1    'fit the array with the polylines
    p_array(1) = p2
    p_array(2) = p3
    p_array(3) = p4

    '**** create an array of region entities 
    '**** "CamBam.CAD.Region" must be used instead to only "Region" to avoid ambiguity with "System.Drawing.Region"

    dim rg() as CamBam.CAD.Region    'an array of regions (more than one can be returned)

    rg = CamBam.CAD.region.CreateFromPolylines(p_array)    'create the regions from the polylines

    for n as long = 0 to UBound(rg)    'add the created regions to the document (more than one region can be created)
        doc.Add(rg(n))
    next n

    View.RefreshView()

end sub