' CamBam VBScript dh42 04/2016
' polyline 3D trim test

sub main

    dim ptool as polyline = new polyline()    ' a closed polyline as tool

    dim p1 as polyline = new polyline()    ' the polylines to trim
    dim p2 as polyline = new polyline()    
    dim p3 as polyline = new polyline()    

'******** erase doc

    View.SelectAllVisibleGeometry()
    CamBamUI.MainUI.DeleteEntities(true)

'********** create the polyline for the test ********

'**** draw a CLOSED polyline as tool ********

    ptool.Add(18,22,0,0)    
    ptool.Add(23,14,0,0)
    ptool.Add(23,-5,0,0)
    ptool.Add(24,-22,0,0)
    ptool.Add(-9,3,0,0)
    ptool.Add(-12,16,0,0)
    ptool.Add(-4,21,0,0)
    ptool.Add(-5,30,0,0)

    ptool.closed = true

    doc.Add(ptool)

'**** draw the 3 polylines to trim

    p1.Add(-18,18,-5,0)
    p1.Add(1,6,-2,0)
    p1.Add(12.5,-2.57,-3,0)
    p1.Add(32.25,-21,-4,0)

    p2.Add(-14,24,-2,0)
    p2.Add(5,12,-3,0)
    p2.Add(16,4,-3,0)
    p2.Add(41,-21,-4,0)

    p3.Add(-8,29,-1,0)
    p3.Add(7,21,-3,0)
    p3.Add(19,12,-2,0)
    p3.Add(47,-16,0,0)

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

'*** 2 shapelist that will contain the lists of polylines to trim and the list of polylines used to trim
'*** and another shapelist that will contain the resulting polylines

    Dim sl_trim as ShapeList = New shapelist    
    Dim sl_trimers as ShapeList = New shapelist    

    Dim sl_dest as ShapeList = New shapelist
    
'*** 2 lists of polyline

    Dim polylist_totrim As System.Collections.Generic.List(Of Polyline) = New System.Collections.Generic.List(Of Polyline)
    Dim polylist_trimers As System.Collections.Generic.List(Of Polyline) = New System.Collections.Generic.List(Of Polyline)

'******* add the polylines to the list of polylines to trim

    polylist_totrim.Add(p1)
    polylist_totrim.Add(p2)
    polylist_totrim.Add(p3)

'******* add the polylines to the list of polylines used to trim (tool)

    polylist_trimers.Add(ptool)

'** add the polyline lists to the ShapeList

    sl_trim.AddEntities(polylist_totrim)
    sl_trimers.AddEntities(polylist_trimers)

'******* trim the polylines, the result falls in sl_dest)

    sl_dest = sl_trim.Trim3D(sl_trimers ,"o")    'trim external, warning the char in the function is case sensitive

    View.RefreshView()

'***** remove all the test polylines

    View.SelectAllVisibleGeometry()
    CamBamUI.MainUI.DeleteEntities(true)

'**** add the resulting polylines to the doc

    For Each item As ShapeListItem In sl_dest
            Doc.Add(item.Shape)
    Next

    View.RefreshView()

end sub