您的位置:首页 > 其它

AutoCAD .Net 监测工作空间变化

2017-12-10 14:03 239 查看
当你需要监测 AutoCAD 工作空间变化事件。

比如:在 AutoCAD经典 工作空间时,加载一般菜单,在 草图与注释 工作空间时,加载Ribbon界面。

可以通过监测系统变量 WSCURRENT 的变化事件实现。

示例代码如下:

using System;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;

namespace HelloAcad2014
{
public class WorkspaceChange
{
[CommandMethod("MonitorWorkspaceChange")]
public void MonitorWorkspaceChange()
{
Application.SystemVariableChanged += new Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(
SystemVariableChanged);
}

void SystemVariableChanged(object sender, Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs e)
{
if (e.Name == "WSCURRENT")
{
string currentWorkspaceName = (string)Application.GetSystemVariable(e.Name);

Document doc = Application.DocumentManager.MdiActiveDocument;
doc.Editor.WriteMessage("Current Workspace: {0}\n", currentWorkspaceName);
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  AutoCAD