# Filename: pl_closed.py
# Purpose: Used for polygon closure.

from maptek import vulcan_gui

# use dynamic selection to select correct object
sel = vulcan_gui.selection("Select closed polygon.")
sel.criteria = ["LINE", "POLYGON"]  # limit selection to a polyline object
sel.single_object = True  # prevents selection prompt from asking more than once

for obj in sel:
    obj_name = obj.get_name()  # get name of object
    
    # get closure state of selected object
    state = obj.closed   
    print(f"{obj_name}: {state}")

    # set closure state of selected object
    obj.closed = True  # close polygon: (True = close, False = open)
    sel.replace(obj)  # replaces the old object and preserves changes

    # report closure state
    if obj.is_closed():
        print(f'{obj_name} is closed.')
    else:
        print(f'{obj_name} is not closed.')    