ElementWrapper.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Autodesk.Revit.DB;
  2. namespace RevitExport.Export
  3. {
  4. /// <summary>
  5. /// 元素包装
  6. /// </summary>
  7. public class ElementWrapper
  8. {
  9. public ElementWrapper(Element element)
  10. {
  11. RefElement = element;
  12. IsRevitElement = true;
  13. UseDefaultCategory();
  14. SourceId = element.Id.ToString();
  15. }
  16. public ElementWrapper(object instance,string sourceId)
  17. {
  18. RefObject = instance;
  19. IsRevitElement = false;
  20. UseDefaultCategory();
  21. SourceId = sourceId;
  22. }
  23. public bool IsRevitElement { get; private set; }
  24. /// <summary>
  25. /// 使用默认的分类
  26. /// </summary>
  27. public void UseDefaultCategory()
  28. {
  29. Category = IsRevitElement ? RefElement.GetType().FullName : RefObject.GetType().FullName;
  30. }
  31. public Element RefElement { get; private set; }
  32. public string Category { get; set; }
  33. public string SourceId { get; private set; }
  34. #region 普通对象处理
  35. public object RefObject{ get; private set; }
  36. public T GetObject<T>()
  37. {
  38. return (T)RefObject;
  39. }
  40. #endregion
  41. }
  42. }