# Filename: tri_contours.py
# Purpose: Gets the contours of a triangulation at a specified Z elevation.
# Returns: Object list.

from maptek import vulcan

input_tri = 'topo.00t'
dgd_file = "pydemo.dgd.isis"  # design database
layer_name = "CONTOUR_150"  # layer to access

# read in triangulation and get contours at z-value.
with vulcan.triangulation(input_tri) as tri: 
    contour_list = tri.contour(150.0) # z-value or elevation

# create layer using contours
with vulcan.dgd(dgd_file, "w") as dgd:
    assert not dgd.is_layer(layer_name), "Error: Layer already exists."
    layer = vulcan.layer(layer_name)
    for obj in contour_list:
        layer.append(obj)  # add line into the layer
    dgd.save_layer(layer)