Revit SDK 介绍:TypeRegeneration 修改类型,更新文档 & ValidateParameters 参数合法性验证

前言

这篇文章介绍两个例子,逻辑比较简单:

  1. TypeRegeneration 修改类型,更新文档
  2. ValidateParameters 参数合法性验证

内容

TypeRegeneration

在这里插入图片描述
FamilyType 不是继承自 Element 的,而是独立于 Element 体系之外,直接从 Autodesk.Revit.DB.APIObject派生。
FamilySymbol 则是继承自 ElementType。

namespace Autodesk.Revit.DB
{
    public class FamilyType : APIObject
    {
        public string Name { get; }
        public double? AsDouble(FamilyParameter familyParameter);
        public ElementId AsElementId(FamilyParameter familyParameter);
        public int? AsInteger(FamilyParameter familyParameter);
        public string AsString(FamilyParameter familyParameter);
        public string AsValueString(FamilyParameter familyParameter);
        public bool HasValue(FamilyParameter familyParameter);
    }
}

TypeRegeneration 修改类型,更新文档。
这个例子是在族文件里运行,因此 document.IsFamilyDocument 返回真。例子的核心是更改当前文档的类型 m_familyManager.CurrentType = type
核心逻辑:

if (document.IsFamilyDocument){
   m_familyManager = document.FamilyManager;
   foreach (FamilyType type in m_familyManager.Types) {
      m_familyManager.CurrentType = type;
   }

ValidateParameters

ValidateParameters 参数合法性验证。
同样是在族文档里面,即 document.IsFamilyDocument 返回真。
遍历所有参数,判断是否合法:

foreach (FamilyType type in familyManager.Types){
   bool right = true;
   foreach (FamilyParameter para in familyManager.Parameters){
      if (type.HasValue(para)){
         switch (para.StorageType){
            case StorageType.Double:
               if (!(type.AsDouble(para) is double))
                  right = false;
                  break;
               case StorageType.ElementId:
                  try{
                     Autodesk.Revit.DB.ElementId elemId=type.AsElementId(para);
                  } catch {
                     right = false;
                  }                                    
                  break;
               case StorageType.Integer:
                  if (!(type.AsInteger(para) is int))
                     right = false;
                  break;
               case StorageType.String:
                  if (!(type.AsString(para) is string))
                     right = false;
                  break;
               default:
                  break;
         }
      }    
   }
} 
namespace Autodesk.Revit.DB
{
    public class FamilyParameter : APIObject
    {
        public bool UserModifiable { get; }
        public override bool IsReadOnly { get; }
        public bool IsShared { get; }
        public Guid GUID { get; }
        public ElementId Id { get; }
        public ParameterSet AssociatedParameters { get; }
        public DisplayUnitType DisplayUnitType { get; }
        public string Formula { get; }
        public bool CanAssignFormula { get; }
        public bool IsDeterminedByFormula { get; }
        public bool IsReporting { get; }
        public bool IsInstance { get; }
        public StorageType StorageType { get; }
        public Definition Definition { get; }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

极客BIM工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值