EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 633|回复: 1
打印 上一主题 下一主题

访问删除的元素Access Deleted Element

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12404

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-9 12:40:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

Here is a question posted by Kristian (Krispy5) Parsons, Systems Analyst - Design at Westfield Design & Construction Pty. Ltd. on accessing deleted element data in the DocumentChanged event handler:
Question: How do I find the category of the deleted elements? When I try to get the Element from the ElementId it fails since the element has already been deleted.
In my case I would like to warn users when they have deleted a Floor.
Answer: I was planning to test your assertion by looking at the Revit SDK ChangesMonitor sample which demonstrates the use of the DocumentChanged method.
I assume that your question is based on using that event to be notified of the deleted elements. Looking at the ChangesMonitor DocumentChanged event handler, I note that it calls a helper method AddChangeInfoRow to list the added, deleted and modified element information in its modeless form. That method includes the following statements and comments which clearly tell you that the deleted element information is no longer accessible:
private void AddChangeInfoRow(  ElementId id,  Document doc,  string changeType ){  // retrieve the changed element  Element elem = doc.get_Element( id );   DataRow newRow = m_ChangesInfoTable.NewRow();   // set the relative information of   // this event into the table.   if( elem == null )  {    // this branch is for deleted element due     // to the deleted element cannot be retrieved     // from the document.     newRow["ChangeType"] = changeType;    newRow["Id"] = id.IntegerValue.ToString();    newRow["Name"] = "";    newRow["Category"] = "";    newRow["Document"] = "";  }  else  {    newRow["ChangeType"] = changeType;    newRow["Id"] = id.IntegerValue.ToString();    newRow["Name"] = elem.Name;     newRow["Category"] = (null == elem.Category)      ? "<null>"       : elem.Category.Name; // added by jeremy     newRow["Document"] = doc.Title;  }  m_ChangesInfoTable.Rows.Add( newRow );}
So the answer to your question is presumably 'no way', and that is as designed.
There is an obvious workaround, though:
The DocumentChanged event is a very simple notification after the fact. The transaction in which the document was modified has already been closed, you cannot do anything more about it yourself, and as we have seen, you cannot even query the deleted elements for their data.
If you wish to access the document before the transaction is closed, there is a very powerful alternative possibility, the dynamic model update framework or DMU. It enables you to register an updater to be triggered by certain events, and also to react on these events within the same transaction that triggered them. It is demonstrated by theDynamicModelUpdate and DistanceToSurfaces SDK samplesand Saikat's Structural DMU sample.
In your case, you can easily implement an updater that simply brings up a message box as described above, and register a trigger for it which reacts to the deletion of floors and nothing else.
Your updater Execute method will be called while the transaction is still open, and you can analyse and even modify the elements being deleted before the transaction is terminated.
Response: Yes that all looks good. By the way, your assumption is correct that I was using the DocumentChanged event.
I looked into the 'dynamic model update framework'. This sounds like what I want.
Later: Thanks again, this solved my problem and was easy to implement.
I filter for floors and use the 'GetChangeTypeElementDeletion' in the 'AddTrigger' call, then in my 'IUpdater' class in the 'Execute' method I simply display a task dialog showing the number of floors being deleted. There is no need for any more filtering, I can just use 'data.GetDeletedElementIds().Count'.

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对
工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-16 21:39

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表