#RTCNA2016 Wish 1 Granted!

Timothy had this API wish:

In Activate View event, If active workset contains “XX”, show task dialog warning user they are about to draw on an incorrect workset. We lock out users from “XX Shared Levels and Grids”, “XX Scope Boxes”, and “XX Links”

public void registerEvent()
    Application app = this.Application;
    UIApplication uiapp = new UIApplication(app);
    uiapp.ViewActivated += new EventHandler<ViewActivatedEventArgs>(uiapp_ViewActivated);

public void uiapp_ViewActivated(object sender, ViewActivatedEventArgs e)
    Document doc = e.Document;
    string activeWorksetName = GetActiveWorkset(doc).Name;
    if (activeWorksetName.Contains("XX"))
        TaskDialog.Show("Warning", "Do not create elements in 'XX' workset: " + activeWorksetName);

public Workset GetActiveWorkset(Document doc)
    // Get the workset table from the document
    WorksetTable worksetTable = doc.GetWorksetTable();
    // Get the Id of the active workset
    WorksetId activeId = worksetTable.GetActiveWorksetId();
    // Find the workset with that Id 
    Workset workset = worksetTable.GetWorkset(activeId);
    return workset;

3 thoughts on “#RTCNA2016 Wish 1 Granted!

  1. Can this be used for View templates? As in warning “you are about to deviate from the company view settings”?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s