简体   繁体   English

创建后的Revit API编辑元素

[英]Revit API Editing Elements After Creation

I have a questions that is more theory of "best practices" than actual technical programming. 我有一个问题,那就是“最佳实践”的理论要比实际的技术编程更多。

I am trying to think of the best way to handle editing an element after it is placed by my program. 我正在尝试考虑在程序放置元素后处理元素的最佳方法。 Specifically I have my program set up as follows: 具体来说,我的程序设置如下:

User clicks a tool that essentially "adds some families into a project" in Revit. 用户单击Revit中的工具,该工具实际上是“将一些族添加到项目中”。 It reads a sketch created by user and places items based on the sketch. 它读取用户创建的草图,并根据该草图放置项目。

Sketch 草图

Element creation 元素创建

I want to give the user the ability to "edit the sketch" of those elements similar to say a floor slab. 我想让用户能够“编辑草图”这些元素,就像说楼板一样。 I don't believe the Revit API exposes the ability to sketch using "sketch mode". 我认为Revit API不会提供使用“草图模式”进行草图绘制的功能。 I am trying to mimic this very useful capability in my program. 我正在尝试在程序中模仿这种非常有用的功能。

So, what I have done is used extensible storage and store an UniqueId into all elements created using my tool. 因此,我所做的就是使用可扩展存储,并将UniqueId存储到使用我的工具创建的所有元素中。 What the program does is when the user clicks "edit elements" tool, the program asks for the new sketch, asks to click on existing element, reads the UniqueId of the existing element and calls all elements with that UniqueId and deletes them, then the program adds new elements into the project again using the users "new sketch". 该程序的作用是,当用户单击“编辑元素”工具时,该程序询问新草图,要求单击现有元素,读取现有元素的UniqueId,并调用具有该UniqueId的所有元素并将其删除,然后程序使用用户“新草图”再次将新元素添加到项目中。

The problem is, if the user deletes the original elements that were added to the project and then tries to edit them, how do I guarantee the user is not going to delete those original elements that have the UniqueId? 问题是,如果用户删除了添加到项目中的原始元素,然后尝试对其进行编辑,那么如何保证用户不会删除那些具有UniqueId的原始元素? I think the way to go is to use the Dynamic Model Update functionality in the Revit API. 我认为解决方法是在Revit API中使用动态模型更新功能。

How are most of these algorithms written? 这些算法中的大多数如何编写? Am I on the right track here? 我在正确的轨道上吗? Do I just assign UniqueIds to elements and store them on the elements themselves so I can call them up later? 我是否只是将UniqueIds分配给元素并将它们存储在元素本身上,以便以后再调用它们? Maybe there is a basic theoretical piece of the puzzle I am missing. 也许我缺少一个基本的理论难题。 Data structures? 数据结构?

I think you are essentially on the right track. 我认为您基本上是在正确的轨道上。

Using extensible storage to store the UniqueIds is definitely the way to go, and also using the DMU dynamic model updater functionality to react to changes sounds good. 使用可扩展的存储来存储UniqueIds绝对是必经之路,而且使用DMU动态模型更新程序功能来对更改做出反应听起来不错。

The one thing that seems to be unclear is the fact the Revit will automatically assign the unique ids to the elements when they are created, and there is nothing you can do to affect that. 似乎还不清楚的一件事是,Revit会在创建元素时自动将唯一的ID分配给元素,您无能为力。 The unique id is unique and immutable, and you have no control over it. 唯一ID是唯一且不可变的,您无法对其进行控制。

Therefore, the easiest approach is probably to delete all the previous sketch elements and recreate the entire sketch and all elements defining it from scratch whenever the sketch needs to be modified in any way. 因此,最简单的方法可能是删除所有先前的草图元素,并在需要以任何方式修改草图时重新创建整个草图以及从头开始定义它的所有元素。

You should use ElementId instead of UniqueId for structured storage, because an ElementId is automatically remapped to the new ElementId when a work sharing update occurs. 您应该使用ElementId而不是UniqueId进行结构化存储,因为发生工作共享更新时,ElementId会自动重新映射到新的ElementId。 The ElementId is also set To ElementId.InvalidElementId when the element is deleted. 删除元素时,还将ElementId设置为ElementId.InvalidElementId。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM