在项目中,我们想把一些不相关的数据记录在构件中,但是,如果全部展示出来,会让设计人员觉得构件很杂很乱。
这时我们需要一些功能去把我们自己想存的数据给存在构件中,而且可以不让设计人员看到。
在2012年的是RevitAPI提供了扩展存储的功能。(Schema)
Schema类
API文档中的备注是这样的:
A Schema is similar to a class in most object-oriented languages, or to a C struct, while an Entity is an object of that class. The Schema object is immutable. To create and populate a Schema, use the SchemaBuilder class. Schemas are stored in the memory of the running instance of Revit and may be retrieved with the Lookup method. When a document containing Entities of a Schema is saved, the Schema is saved with the document too. Opening that document reintroduces the Schema into memory. As you plan to store your data in Revit, please be aware that the data will be stored in Revit elements. Overwhelming the Revit database will impact performance and stability, and will make the user unhappy. Also, remember that multiple add-ins may be storing their data simultaneously. Several kB per element or several MB per file are reasonable maximums for one add-in. If you have larger requirements, consider storing them in a separate database (such as SQLite) and storing keys into that database in Revit.
翻译:Schema类似于大多数面向对象语言中的类或者类似于C结构,而实体(Entity)是该类的对象。Schema对象是不可变的。要创建和填充一个Schema,请使用SchemaBuilder类。Schemas存储在正在运行的Revit实例的内存中,可以使用Lookup进行检索。当一个包含Schema的实体文档被保存时,Schema也将与文档一起保存。打开该文档会将Schema重新引入内存。当您计划在Revit中存储数据时,请注意,数据将存储在Revit元素中。Revit数据库不堪重负将影响性能和稳定性,并且会影响用户体验。另外,请记住,多个加载项可能会同时存储其数据。对于一个加载项,每个元素几kB或每个文件几MB是合理的最大值。如果您有更大的要求,请考虑将它们存储在单独的数据库(例如SQLite)中,并将密钥存储到Revit中的该数据库中。
所以当我们需要给图元增加Schema的时候,一定要注意,尽量让每一个element只存储几kB的信息,如果存储的信息过大,可能会导致Revit卡死或者崩溃。
Guid参数
全局唯一标识符(GUID,Globally Unique Identifier)是一种由算法生成的二进制长度为128位的数字标识符。GUID主要用于在拥有多个节点、多台计算机的网络或系统中。在理想情况下,任何计算机和计算机集群都不会生成两个相同的GUID。GUID 的总数达到了2128(3.4×1038)个,所以随机生成两个相同GUID的可能性非常小,但并不为0。所以,用于生成GUID的算法通常都加入了非随机的参数(如时间),以保证这种重复的情况不会发生。
我们可以在VS中直接生成,点击工具选项卡–>点击创建GUID
或者自己将生成GUID的方法写进代码中
生成GUID参数有6种方法:
var uuid = Guid.NewGuid().ToString();//默认格式:965bf2bb-eea7-4e15-ab7e-b803ae0100a0
var uuidN = Guid.NewGuid().ToString("N");//N--->32位:8D70EEA0E31B4349B6C6214B7AB04CEC
var uuidD = Guid.NewGuid().ToString("D");//D--->由连字符分隔的32位:8DFDEADB - C0EB - 4D47 - B9F5 - CC5172