Opening Database Windows (Python)

Opening Database Windows (Python)
  1# This script shows how to display Database Windows for both internal and external tables
  2# including for child tables by supplying a parent key
  3ui = impact.gui
  4ot = ui.output_toolbox
  5
  6db = impact.active_database
  7ad = impact.active_drawing
  8
  9ot.clear()  # open the configured CUSTOMER Database Window (either built-in CUSTOMER or remote customer table)
 10if ui.open_database_window("CUSTOMER", None):
 11
 12    ot.add("A CUSTOMER record was modified")
 13
 14if not ad.isNone():
 15
 16    # open the configured layer type Database Window (for the impact.active_layer)
 17    if ui.open_database_window(ad.active_layer.layer_type, None):
 18
 19        ot.add(ad.active_layer.layer_type + " information was modified")
 20
 21    # open the integrated Database Window
 22    if ui.open_database_window("<INTEGRATED>", None):
 23
 24        ot.add("Something was changed in the impact.active_drawing")
 25
 26# open a specific Database Window directly
 27dbw = db.find_master_tool_setting("Palettes", ipMasterSettingType.mstDBWindow)
 28
 29if not dbw.isNone():
 30
 31    ot.add("Successfully located setting " + dbw.full_name)
 32    ui.open_database_window2(dbw, None)
 33
 34else:
 35
 36    ot.add("Unable to locate Database Window 'Palettes'")
 37
 38# the following examples use advanced database window options
 39
 40# open the configured impact.drawings Database Window in read only mode
 41if not ad.isNone():
 42    opts = ui.create_database_window_options()
 43
 44    opts.read_only = True
 45    ui.open_database_window("impact.drawings", opts)
 46
 47# open a Database Window for a specific layer even when it isn't current
 48if not ad.isNone():
 49    layer = None
 50    try:
 51        layer = ad.layers("B")
 52    except Exception as exc:
 53        pass
 54    impact.gui.output_toolbox.add(f"Failed to create object via ad.layers(): {exc}")
 55
 56    if not (layer.isNone()):
 57
 58        if ad.active_layer.full_name != layer.full_name:
 59            opts = ui.create_database_window_options()
 60
 61            opts.drawing = ad
 62            opts.layer = layer
 63            ui.open_database_window(opts.layer.layer_type, opts)
 64
 65        else:
 66
 67            ot.add("Layer 'B' is the active layer in the active drawing")
 68
 69    else:
 70
 71        ot.add("Unable to locate layer 'B' in the active drawing")
 72
 73# open the configured CUSTOMER Database Window and scroll to the current customer
 74if not ad.isNone():
 75    opts = ui.create_database_window_options()
 76
 77    opts.primary_key = ad.customer.key
 78    opts.operation = ipDatabaseWindowOperation.dwoScrollToPrimaryKey
 79    ui.open_database_window("CUSTOMER", opts)
 80
 81    ui.show_message(ipShowMessageType.smtInfo, "Old Primary Key: " + str(ad.customer.key) + ", New Primary Key: " + str(opts.primary_key), None)
 82
 83# open the configured SALESREP Database Window and add a new record
 84opts = ui.create_database_window_options()
 85
 86opts.operation = ipDatabaseWindowOperation.dwoAdd
 87
 88if ui.open_database_window("SALESREP", opts):
 89
 90    ui.show_message(ipShowMessageType.smtInfo, "Added new SALESREP with Primary Key: " + str(opts.primary_key), None)
 91
 92# open the configured CUSTOMER Database Window and edit the current customer
 93if not ad.isNone():
 94    opts = ui.create_database_window_options()
 95
 96    opts.primary_key = ad.customer.key
 97    opts.operation = ipDatabaseWindowOperation.dwoChange
 98    ui.open_database_window("CUSTOMER", opts)
 99
100# open the specific  # ADDRESS List' Database Window for the current customer
101# this uses a Parent/Child relationship to show only those addresses for the customer
102dbw = db.find_master_tool_setting("ADDRESS List", ipMasterSettingType.mstDBWindow)
103
104if not (ad.isNone()) and not (dbw.isNone()):
105    opts = ui.create_database_window_options()
106
107    opts.parent_table_name = "CUSTOMER"
108    opts.parent_key_value = ad.customer.key
109    opts.child_column_name = "A_CUSTKEY"
110    opts.window_title = "Addresses for " + ad.customer.name
111    ui.open_database_window("ADDRESS", opts)
112
113else:
114
115    ot.add("Unable to locate the Database Window 'ADDRESS List'")