# Filename: pl_set_coordinates.py
# Purpose: Create a line from a list of points.
# Returns: Bool.

from maptek import vulcan

dgd_file = "pydemo.dgd.isis"  # design database to access
layer_name = "POINTS"  # layer to access
points = [[75912.0, 3797.0, 0.0],
          [76707.0, 3693.0, 0.0],
          [77476.0, 3523.0, 0.0],
          [78428.0, 3523.0, 0.0],
          [79496.0, 3901.0, 0.0],
          [80252.0, 4214.0, 0.0],
          [80813.0, 4553.0, 0.0],
          [81438.0, 5048.0, 0.0]]

with vulcan.dgd(dgd_file, "w") as dgd:  # open up the database in write mode
    if dgd.is_layer(layer_name):
        layer = dgd.get_layer(layer_name)  # get layer
        print('Layer exists')
    else:
        layer = vulcan.layer(layer_name)  # create a new layer
        print('new layer created')

    line = vulcan.polyline(points)  # create new polyline object
    
    line.set_coordinates(points)  # set the coordinates of a line
    
    line.set_connected()  # connect the points
    line.set_colour(5)  # give the line a colour
    layer.append(line)  # add line layer
    dgd.save_layer(layer)  # save layer