前言
这个例子介绍 Revit 的单位设定,和通过UI去做设定是一致的,目的是为用户提供一些自动化的空间。
内容
API 和 UI 功能基本一致。
运行程序得到结果:
Revit UI 启动单位设置的结果:
API
核心功能在 Document
的方法:public void SetUnits(Units units)
using (Autodesk.Revit.DB.Transaction tran = new Autodesk.Revit.DB.Transaction(document, "SetUnits"))
{
tran.Start();
document.SetUnits(units);
tran.Commit();
}
Units API 接口:
namespace Autodesk.Revit.DB
{
public class Units : IDisposable
{
// UnitSystem 可以是米制或者英制
public Units(UnitSystem unitSystem);
~Units();
// 每组的数字的数量,2个数字或者3个数字
public DigitGroupingAmount DigitGroupingAmount { get; set; }
// 数字分组符号,点、逗号、空格等5种可选
public DigitGroupingSymbol DigitGroupingSymbol { get; set; }
// 十进制符号,点或者逗号
public DecimalSymbol DecimalSymbol { get; set; }
// 得到所有可以修改的单位,注意返回的是 ForgeTypeId
public static IList<ForgeTypeId> GetModifiableSpecs();
// 判断对应的 ForgeTypeId 的单位是否可以修改
public static bool IsModifiableSpec(ForgeTypeId specTypeId);
// 得到对应FrogeTypeId的单位格式
public FormatOptions GetFormatOptions(ForgeTypeId specTypeId);
// 设置对应FrogeTypeId的单位格式,已经被废弃
public void SetFormatOptions(ForgeTypeId specTypeId, FormatOptions options);
// 原来以 UnitType 单位为标注的已经被废弃
// 判断对应的 UnitType 单位是否可以修改,已经被废弃
[Obsolete("This method is deprecated in Revit 2021 and may be removed in a future version of Revit. Please use the `IsModifiableSpec(ForgeTypeId)` method instead.")]
public static bool IsModifiableUnitType(UnitType unitType);
// 得到对应UnitType的单位格式,已经被废弃
[Obsolete("This method is deprecated in Revit 2021 and may be removed in a future version of Revit. Please use the `GetFormatOptions(ForgeTypeId)` overload instead.")]
public FormatOptions GetFormatOptions(UnitType unitType);
// 对应UnitType的单位格式
[Obsolete("This method is deprecated in Revit 2021 and may be removed in a future version of Revit. Please use the `SetFormatOptions(ForgeTypeId, FormatOptions)` overload instead.")]
public void SetFormatOptions(UnitType unitType, FormatOptions options);
// 得到所有可以修改的单位,已经被废弃
[Obsolete("This method is deprecated in Revit 2021 and may be removed in a future version of Revit. Please use the `GetModifiableSpecs()` method instead.")]
public static IList<UnitType> GetModifiableUnitTypes();
public bool IsValidObject { get; }
public sealed override void Dispose();
[HandleProcessCorruptedStateExceptions]
protected virtual void Dispose(bool A_0);
protected virtual void ReleaseUnmanagedResources(bool disposing);
}
}
ForgeTypeId
ForgeTypeId 的接口:
namespace Autodesk.Revit.DB
{
// 每个 ForgeTypeId 对应一个 Forge schema.
public class ForgeTypeId : IDisposable
{
public ForgeTypeId();
public ForgeTypeId(string typeId);
~ForgeTypeId();
public string TypeId { get; set; }
public ForgeTypeId Clear();
public sealed override void Dispose();
public bool Empty();
public override bool Equals(object other);
public override int GetHashCode();
public bool NameEquals(ForgeTypeId other);
public bool StrictlyEquals(ForgeTypeId other);
[HandleProcessCorruptedStateExceptions]
protected virtual void Dispose(bool A_0);
protected virtual void ReleaseUnmanagedResources(bool disposing);
public static bool operator ==(ForgeTypeId lhs, ForgeTypeId rhs);
}
}
输出ForgeTypeId
的内容:
系统提供的 ForgeTypeId
,对应了单位中的各个选项: