编程获取在协同共享模型中获得Revit对象的所有者
2014-03-28 14:43
211 查看
近期写了一篇文章说明如何获取共享模型中构件的所有者。在共享模型中,每一个构件都有一个work set,可以编程获取该work set的所有者。
下面是一个小示例。
原文链接:点击打开原文
为了方便,将文章摘录如下:
For any visible element in a Revit shared model, we can get this element’s work set work set id by Document.GetWorksetId() method. Then you can retrieve the corresponding WorkSet object by WorkSetTable.GetWorkSet() method. WorkSet.Owner returns the work set’s owner name. Finally compare the work set owner with Revit current user name.
Here is the simplest code to show the process.
using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms; using Autodesk.Revit.DB;using Autodesk.Revit.UI;using Autodesk.Revit.ApplicationServices;using Autodesk.Revit.Attributes;using Autodesk.Revit.UI.Selection; [TransactionAttribute(TransactionMode.Manual)]public class RevitCommand : IExternalCommand{ public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; Transaction trans = new Transaction(doc); trans.Start("testComamnd"); Selection sel = app.ActiveUIDocument.Selection; Reference ref1 = sel.PickObject(ObjectType.Element, "pick an element"); Element elem = doc.GetElement(ref1); // code changing this element here. // for simplicity, no change here. //Get the workset information. WorksetId idWS = doc.GetWorksetId(elem.Id); WorksetTable table = doc.GetWorksetTable(); Workset ws = table.GetWorkset(idWS); string owner = ws.Owner; trans.Commit(); //Compare with the current user. if (owner == app.Application.Username) { TaskDialog.Show("Synchronize reminder", "The picked element was updated, please synchronize the document"); } return Result.Succeeded; }}
下面是一个小示例。
原文链接:点击打开原文
为了方便,将文章摘录如下:
For any visible element in a Revit shared model, we can get this element’s work set work set id by Document.GetWorksetId() method. Then you can retrieve the corresponding WorkSet object by WorkSetTable.GetWorkSet() method. WorkSet.Owner returns the work set’s owner name. Finally compare the work set owner with Revit current user name.
Here is the simplest code to show the process.
using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms; using Autodesk.Revit.DB;using Autodesk.Revit.UI;using Autodesk.Revit.ApplicationServices;using Autodesk.Revit.Attributes;using Autodesk.Revit.UI.Selection; [TransactionAttribute(TransactionMode.Manual)]public class RevitCommand : IExternalCommand{ public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; Transaction trans = new Transaction(doc); trans.Start("testComamnd"); Selection sel = app.ActiveUIDocument.Selection; Reference ref1 = sel.PickObject(ObjectType.Element, "pick an element"); Element elem = doc.GetElement(ref1); // code changing this element here. // for simplicity, no change here. //Get the workset information. WorksetId idWS = doc.GetWorksetId(elem.Id); WorksetTable table = doc.GetWorksetTable(); Workset ws = table.GetWorkset(idWS); string owner = ws.Owner; trans.Commit(); //Compare with the current user. if (owner == app.Application.Username) { TaskDialog.Show("Synchronize reminder", "The picked element was updated, please synchronize the document"); } return Result.Succeeded; }}
相关文章推荐
- 编程获取Revit视图中的所有实例对象数量
- JavaScript DOM编程基础精华01(DOM入门,DOM模型和获取页面元素,事件,window对象的方法)
- JavaScript DOM编程基础精华01(DOM入门,DOM模型和获取页面元素,事件,window对象的方法)
- JavaScript---网络编程(6)-Dom和Bom模型概念讲解(节点获取,window对象)
- 编程如何获得通过草图创建的Revit构件关联的原始草图对象
- JavaScript---网络编程(6)-Dom和Bom模型概念讲解(节点获取,window对象)
- Java多线程编程(六)-并发编程原理(Java存储模型和共享对象)
- vc++MCF/C++/C中怎样让应用程序获得或以管理员权限运行 ,ShellExecuteEX编程 --- 获取管理员权限
- java并发编程实战-对象的共享
- GMF中,由xxxEditPart获得模型对象的方法的方法
- 可否编程对链接模型进行修改或选择链接模型中的对象?
- 客户端网页编程-第五章-文档对象模型DOM
- thinkphp3.2源码----获取并保存模型对象与数据库连接实例
- 如何获取Revit工作集中的对象?
- JavaScript---BOM模型之window对象,DOM模型的节点获取
- Strust2 --- 根据泛型封装Action的模型驱动ModelDriven<T>获取model对象
- Microsoft Office VB.NET编程,获得当前编辑文档的对象,并打印到控制台
- 共享内存的编程模型
- thinkphp5 模型实例化 获得数据对象
- Revit二次开发高级专题讲座:访问Revit模型中的几何数据以及对象间关系判断方法(点击下载)