Configuration Table Sample

Description

Creates a configuration table on the active sheet and updates its basic display settings.

Code Samples

"""Create a configuration table and update simple display settings."""

import adsk.core
import adsk.drawing
import traceback


def run(context):
    app = None
    ui = None

    try:
        app = adsk.core.Application.get()
        ui = app.userInterface if app else None

        drawing = adsk.drawing.Drawing.cast(app.activeProduct) if app else None
        if not drawing:
            drawing_doc = adsk.drawing.DrawingDocument.cast(app.activeDocument) if app else None
            drawing = drawing_doc.drawing if drawing_doc else None
        if not drawing or not drawing.activeSheet:
            return

        sheet = drawing.activeSheet
        config_tables = sheet.configurationTables
        if not config_tables:
            return

        table_input = config_tables.createInput()
        if not table_input:
            return

        table_input.title = "Configuration Table API Sample"
        table_input.direction = adsk.drawing.TableDirectionTypes.UpTableDirectionType

        created_index = config_tables.count
        config_table = config_tables.add(table_input)
        if not config_table:
            return

        if config_tables.count <= created_index:
            return
        config_table.title = "Configuration Table API Sample Updated"
        config_table.direction = adsk.drawing.TableDirectionTypes.DownTableDirectionType

    except:
        if app:
            app.log(traceback.format_exc())
        if ui:
            ui.messageBox("Failed:\n{}".format(traceback.format_exc()))