编程获取在协同共享模型中获得Revit对象的所有者


近期写了一篇文章说明如何获取共享模型中构件的所有者。在共享模型中,每一个构件都有一个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;

    }

}

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值