Revit API扩展存储Extensible Storage

Revit 2012 API提供扩展存储Extensible Storage 来向revit文件附加数据。
这里是把数据附加到实体,参看附加到项目文件ProjectInfo示例
using  System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Text;

using  WinForm  =  System.Windows.Forms;

using  Autodesk.Revit.UI;
using  Autodesk.Revit.DB;
using  Autodesk.Revit.Attributes;

using  Autodesk.Revit.DB.Mechanical;
using  Autodesk.Revit.UI.Selection;
using  Autodesk.Revit.ApplicationServices;

using  Autodesk.Revit.DB.Structure;
using  Autodesk.Revit.DB.ExtensibleStorage;

using  System.Xml;

namespace  RevitCodes
{
    [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    
public   class  cmdStore : IExternalCommand
    {
        
public  Result Execute(ExternalCommandData commandData,  ref   string  messages, ElementSet elements)
        {

            UIApplication app 
=  commandData.Application;
            Document doc 
=  app.ActiveUIDocument.Document;

            Reference refWall 
=  app.ActiveUIDocument.Selection.PickObject(ObjectType.Element,  " 选择墙 " );
            Wall wall 
=  doc.GetElement(refWall)  as  Wall;
            XYZ xyz 
=  app.ActiveUIDocument.Selection.PickPoint( " 选择一个点 " );
            StoreDataInWall(wall, xyz);

            
return  Result.Succeeded;
        }

        
public   void  StoreDataInWall(Wall wall, XYZ dataToStore)
        {

            Transaction createSchemaAndStoreData 
=   new  Transaction(wall.Document,  " tCreateAndStore " );

            createSchemaAndStoreData.Start();

            SchemaBuilder schemaBuilder 
=

               
new  SchemaBuilder( new  Guid( " 720080CB-DA99-40DC-9415-E53F280AA1F0 " ));

            
//  allow anyone to read the object 

            schemaBuilder.SetReadAccessLevel(AccessLevel.Public);

            
//  restrict writing to this vendor only 

            schemaBuilder.SetWriteAccessLevel(AccessLevel.Vendor);

            
//  required because of restricted write-access 

            schemaBuilder.SetVendorId(
" ADSK " );

            
//  create a field to store an XYZ 

            FieldBuilder fieldBuilder 
=

               schemaBuilder.AddSimpleField(
" WireSpliceLocation " typeof (XYZ));

            fieldBuilder.SetUnitType(UnitType.UT_Length);

            fieldBuilder.SetDocumentation(
" A stored location value representing a wiring splice in a wall. " );

            schemaBuilder.SetSchemaName(
" WireSpliceLocation " );

            Schema schema 
=  schemaBuilder.Finish();  //  register the Schema object 

            
//  create an entity (object) for this schema (class) 

            Entity entity 
=   new  Entity(schema);

            
//  get the field from the schema 

            Field fieldSpliceLocation 
=  schema.GetField( " WireSpliceLocation " );

            entity.Set
< XYZ > (fieldSpliceLocation, dataToStore, DisplayUnitType.DUT_METERS);  //  set the value for this 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);

            createSchemaAndStoreData.Commit();

        }

    }

}
from: http://revit.5d6d.com/thread-1289-1-1.html
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值