Monitor workspace change

By Adam Nagy

If you need to monitor the workspace change, e.g. so that you can update the Ribbon with the controls you placed using the Ribbon Runtime API, then you can listen to the system variable changed event, and watch out for WSCURRENT

using System;         using Autodesk.AutoCAD.Runtime;    using acApp = Autodesk.AutoCAD.ApplicationServices.Application;    using Autodesk.AutoCAD.ApplicationServices;         [assembly:CommandClass(typeof(TestProject.Commands))]         namespace TestProject    {      public class Commands      {        [CommandMethod("MonitorWorkspaceChange")]        public void MonitorWorkspaceChange()        {          acApp.SystemVariableChanged +=             new SystemVariableChangedEventHandler(              acApp_SystemVariableChanged);        }             void acApp_SystemVariableChanged(          object sender, SystemVariableChangedEventArgs e)        {          if (e.Name == "WSCURRENT")          {            string currentWorkspaceName =               (string)acApp.GetSystemVariable(e.Name);                 // Do whatever you need          }        }      }    }

Comments

2 responses to “Monitor workspace change”

  1. I think you also have to monitor the Profile changing. For example, if a user changes the profile via the options command, I don’t believe the WSCURRENT setting notifies that the workspace has changed.

  2. Thank you for the comment.
    Even then the event for WSCURRENT does seem to fire – first with an empty string, then with the actual workspace name.
    I checked it in AutoCAD 2012.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading