您的位置:首页 > 编程语言

编程获取在协同共享模型中获得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; }}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐