Revit API 开发 (10): ExtensibleStorage 外部存储
前言
很多时候,需要往Revit的文件里面放自己的数据。这里简单介绍一下 Revit API 如何处理数据的保存和读取,并且这些数据是绑定到具体的构件上的。另外,也可以自己创建一个 DataStorage 的 element,把信息存储在它里面,这样就不用依赖于某个具体的构件了。
实例
创建一个数据结构,绑定到墙的实例上,存储值,然后再把它读出来。
创建SchemaBuilder
SchemaBuilder schemaBuilder = new SchemaBuilder(new Guid("720080CB-DA99-40DC-9415-E53F280AA1F0"));
schemaBuilder.SetReadAccessLevel(AccessLevel.Public); // allow anyone to read the object
schemaBuilder.SetWriteAccessLevel(AccessLevel.Vendor); // restrict writing to this vendor only
schemaBuilder.SetVendorId("ADSK"); // required because of restricted write-access
schemaBuilder.SetSchemaName("WireSpliceLocation");
创建SchemaBuilder的Field
可以设定 Field 的类型、单位和文档说明。
FieldBuilder fieldBuilder = schemaBuilder.AddSimpleField("WireSpliceLocation", typeof(XYZ)); // create a field to store an XYZ
fieldBuilder.SetUnitType(UnitType.UT_Length);
fieldBuilder.SetDocumentation("A stored location value representing a wiring splice in a wall.");
完成SchemaBuilder的创建
Schema schema = schemaBuilder.Finish(); // register the Schema object
创建一个entity
每一个 Entity 对应到一个 Field,在 Entity 里面可以设置它的值。
Entity entity = new Entity(schema); // create an entity (object) for this schema (class)
Field fieldSpliceLocation = schema.GetField("WireSpliceLocation"); // get the field from the schema
entity.Set<XYZ>(fieldSpliceLocation, dataToStore, DisplayUnitType.DUT_METERS); // set the value for this entity
存储和读取
一个具体的 Entity 可以绑定到某一个具体的构件上面,这里是墙。
wall.SetEntity(entity); // store the entity in the element// get the data back from the wall
Entity retrievedEntity = wall.GetEntity(schema);
XYZ retrievedData = retrievedEntity.Get<XYZ>(schema.GetField("WireSpliceLocation"), DisplayUnitType.DUT_METERS);
完整代码
// 创建一个数据结构,绑定到墙的实例上,存储值,然后再把它读出来。
void StoreDataInWall(Wall wall, XYZ dataToStore)
{using (Transaction createSchemaAndStoreData = new Transaction(wall.Document, "tCreateAndStore")){createSchemaAndStoreData.Start();SchemaBuilder schemaBuilder = new SchemaBuilder(new Guid("720080CB-DA99-40DC-9415-E53F280AA1F0"));schemaBuilder.SetReadAccessLevel(AccessLevel.Public); // allow anyone to read the objectschemaBuilder.SetWriteAccessLevel(AccessLevel.Vendor); // restrict writing to this vendor onlyschemaBuilder.SetVendorId("ADSK"); // required because of restricted write-accessschemaBuilder.SetSchemaName("WireSpliceLocation");FieldBuilder fieldBuilder = schemaBuilder.AddSimpleField("WireSpliceLocation", typeof(XYZ)); // create a field to store an XYZfieldBuilder.SetUnitType(UnitType.UT_Length);fieldBuilder.SetDocumentation("A stored location value representing a wiring splice in a wall.");Schema schema = schemaBuilder.Finish(); // register the Schema objectEntity entity = new Entity(schema); // create an entity (object) for this schema (class)Field fieldSpliceLocation = schema.GetField("WireSpliceLocation"); // get the field from the schemaentity.Set<XYZ>(fieldSpliceLocation, dataToStore, DisplayUnitType.DUT_METERS); // set the value for this entitywall.SetEntity(entity); // store the entity in the element// get the data back from the wallEntity retrievedEntity = wall.GetEntity(schema);XYZ retrievedData = retrievedEntity.Get<XYZ>(schema.GetField("WireSpliceLocation"), DisplayUnitType.DUT_METERS);createSchemaAndStoreData.Commit(); }
}
更多信息
Schema.ListFields 列出 schema 中所有的 field,按字母排序。
Schema.ListSchemas 列出所有的 schema,这是一个静态方法。
Schema.Lookup 通过 GUID 查找 schema,这是一个静态方法。
Revit API 开发 (10): ExtensibleStorage 外部存储相关推荐
- Revit API 开发(12): Revit 文件存储结构
整理(很多内容非原创,转载自网络) 链接来自 The Building Coder: Open Revit OLE Storage RVT File Version RVT and RFA Thumb ...
- Revit API 开发周边:对 Element 进行 Reflection
前言 RevitLookup 可以找到任意一个构建的 BoundingBox,但是我用 API 直接调用却不能,这是什么原因的?到底有没有这个属性 BoundingBox. 内容 对 Element ...
- Revit API 开发(14): RevitLink - 链接文件 rvt,IFC,DWG等
前言 本文对 Revit 链接做一个简单的笔记,以便日后可以查询. 下图中,RVT 和 IFC 都会出现在 Revit 链接的列表里面,他们是 RevitLinkType.而 DWG 及其它文件则不会 ...
- Android内部存储与外部存储(私有目录与公共目录)图文详解
目录 一.存储空间概述 二.存储空间的划分 1.存储划分 2.内部存储 2.1 内部存储概述 2.2 内部存储 - 私有目录 3. 外部存储 3.1 外部存储概述 3.2 外部存储 - 私有目录 3. ...
- Revit API: Dimension 尺寸标注
前言 本文介绍 Revit API 的尺寸标注. 内容 在 Revit API 中,尺寸标注相关的有三个类:Dimension.AngularDimension 和 SpotDimension. 后两 ...
- Revit API:Element 继承体系
继 "Revit API 开发周边:得到 Element 的所有子类" 之后,整理了一下所有 Element 的子类,内容源自 Revit SDK 中的 RevitAPI.chm ...
- 【Revit二次开发】模型中存储数据——参数和外部存储(Parameter, Schema and Entity)
模型中存储数据 参数 读取 写入 外部存储 Schema Entity 快速获取外部存储参数 参数 在Revit平台API中,每个图元对象都有参数属性,它是隶属于图元所有属性的集合,在此集合中更改属性 ...
- Android开发--文件系统中的内部存储和外部存储最全解析 附文件数据保存操作封装
文件存储 前言 文件存储 内存 内部存储 外部存储 内部存储操作 API 读写操作 外部存储操作 公共目录 私有目录 私有文件 私有缓存 文件各种操作封装 前言 众所周知,数据存储在每个应用中都会用到 ...
- Revit二次开发5、外部事件(ExternalEvent)
Revit二次开发5.外部事件(ExternalEvent) 外部事件ExternalEvent简介 事件 外部事件 实现步骤 外部事件的实现 实现IExternalEventHandler接口 Ex ...
最新文章
- 乐安全 支持x86_国产EDA又进一步!芯华章发布全新仿真技术:x86、ARM等架构通吃...
- UVA 10167 - Birthday Cake
- 绑定Service的三种实现方式之使用Messenger
- jvm调优:jmap -histo的使用
- Hive 时间戳和日期相互转换
- 异常排查_Python-日志模块.NoSectionError: No section: '*' 错误?
- FastCGI介绍(快速通用网关接口)
- 【异常】java.lang.NoClassDefFoundError: com/lowagie/text/pdf/PdfContentByte
- Android开发规范:资源文件命名规范
- 【FPGA】FPGA程序的固化和下载(sd卡)
- 分布式操作系统 - 1.分布式系统概论
- 微信 获取signature签名
- 面包店利用拼团模式面包免费送-月销售30万 !
- 笔画输入法教程――如何学习笔画输入法
- 全网最新最全的jmeter接口测试,压力测试
- origin画误差阴影
- asp.net报错:ConnectionString 属性尚未初始化
- python中import上级文件夹
- LeetCode 695.岛屿的最大面积
- 北京软件测试报告,北京PMLAB软件测试报告