Active Layer Change (After) Auto-Task

Active Layer Change (After) Auto-Task
 1# This example shows how to use the Active Layer Change (After) automation task to automate the time
 2# spent by a designer working on a layer. It uses an IGlobal session variable to store
 3# the start time, but you could use any mechanism you like such as a file or a database record.
 4#
 5# It is important to use the IDatabase.auto_task_drawing and IDatabase.auto_task_layer rather than
 6# IDrawings.active_drawing or IDrawing.active_layer
 7#
 8# You should see the Active Layer Change (Before)  example to see how it processes the actual time
 9# spent on the Layer.
10import datetime
11
12# Create a local variable for the output toolbox
13ot = impact.gui.output_toolbox
14
15# Create a local variable for the database
16db = impact.active_database
17
18# Determine if a previous LayerStartTime IGlobal object has been saved
19global_value = db.globals.item("LayerStartTime")
20
21# Create a local variable for the drawing and layer to work on
22drawing = db.auto_task_drawing
23layer = db.auto_task_layer
24
25# get the current impact.system time
26starttime = datetime.datetime.now()
27
28# output a message about the layer and start time
29ot.add("Layer " + layer.full_name + " of Project " + drawing.full_name + " now current (" + str(starttime.isoformat()) + ")")
30
31# add or update the IGlobal object to store the start time
32if global_value.isNone():
33    db.globals.add("LayerStartTime", starttime)
34else:
35    global_value.value = starttime
36