使用ProjectInfo保存文件级别的额外信息

为了保存文件级别的额外信息,可以将共享数据添加到 ProjectInfo 对象中。
ProjectInfo 在一个 Document 中只有一个对象。 ProjectInfo BuildInCategory 成员是 OST_ProjectInformation.

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  RevitApp  =  Autodesk.Revit.ApplicationServices;

using  System.Data;
using  System.Data.SQLite;
using  System.Data.Common;
using  System.Xml;
using  Autodesk.Revit.DB.Analysis;
using  Autodesk.Revit.DB.ExtensibleStorage;

namespace  RevitCodes
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    
// [Journaling(JournalingMode.NoCommandData)]
     public   class  cmdInfo : IExternalCommand
    {
        
public  Result Execute(ExternalCommandData cmdData,  ref   string  msg, ElementSet elements)
        {
            UIDocument uiDoc 
=  cmdData.Application.ActiveUIDocument;
            Selection selection 
=  uiDoc.Selection;
            Document document 
=  uiDoc.Document;


            XYZ xyzTmp 
=   new  XYZ( 10 20 30 );

            Transaction ts 
=   new  Transaction(uiDoc.Document,  " ts " );
            ts.Start();
            
/*
            
*/
            SchemaBuilder schemaBuilder 
=   new  SchemaBuilder(System.Guid.NewGuid());

            
//  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, xyzTmp, DisplayUnitType.DUT_METERS);  //  set the value for this entity 

            document.ProjectInformation.SetEntity(entity);


            
// Schema schema = null;
            Entity retrievedEntity  =  document.ProjectInformation.GetEntity(schema);

            XYZ retrievedData 
=  retrievedEntity.Get < XYZ > (schema.GetField( " WireSpliceLocation " ), DisplayUnitType.DUT_METERS);

            TaskDialog.Show(
" xyz " , retrievedData.X  +   " , "   +  retrievedData.Y  +   " , "   +  retrievedData.Z);

            ts.Commit();
            
return  Result.Succeeded;
        }
    }
}
from: http://revit.5d6d.com/thread-1218-1-1.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值