CopyParameterValue.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* ==============================================================================
  2. * 功能描述:同步幕墙的本地名称、本地编码到幕墙嵌板中?
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/7/11 14:34:26
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using Autodesk.Revit.DB;
  11. using Saga.PlugIn.ModelCheck;
  12. using SAGA.DotNetUtils.Extend;
  13. using SAGA.DotNetUtils.Others;
  14. using SAGA.RevitUtils.Extends;
  15. namespace Saga.PlugIn.Other
  16. {
  17. /// <summary>
  18. /// CheckEquipInSpace
  19. /// </summary>
  20. public class CopyParameterValue
  21. {
  22. public static string AllStr = "All";
  23. private ObservableCollection<PropertyItem> m_parameterDic;
  24. private string m_copyFamilyRange;
  25. public bool SetCopyParameterDic(ObservableCollection<PropertyItem> dic, string copyRange)
  26. {
  27. m_parameterDic = dic;
  28. m_copyFamilyRange = copyRange;
  29. return (dic.Any()&&!string.IsNullOrWhiteSpace(m_copyFamilyRange));
  30. }
  31. public string Execute(Document doc)
  32. {
  33. try
  34. {
  35. OperateFloor(doc);
  36. doc.Save();
  37. }
  38. catch (Exception e)
  39. {
  40. MessageShowBase.Show(e);
  41. }
  42. return null;
  43. }
  44. private void OperateFloor(Document doc)
  45. {
  46. using (Transaction trans = new Transaction(doc, "复制属性"))
  47. {
  48. try
  49. {
  50. trans.Start();
  51. var elements = doc.GetFamilyInstances();
  52. var codes = GetCodes();
  53. foreach (Element element in elements)
  54. {
  55. var code = element.GetFamilyCode();
  56. if (codes.Contains(AllStr) || code.Contains(code))
  57. foreach (var pair in m_parameterDic)
  58. {
  59. string origin = pair.Name;
  60. string target = pair.Value;
  61. if (origin.IsNotNullEmpty() && target.IsNotNullEmpty())
  62. {
  63. element.SetParameterValue(target, element.GetParameterString(origin));
  64. }
  65. }
  66. }
  67. trans.Commit();
  68. }
  69. catch (Exception e)
  70. {
  71. Console.WriteLine(e);
  72. }
  73. }
  74. }
  75. private string[] GetCodes()
  76. {
  77. var codes = m_copyFamilyRange?.Split(';', ';');
  78. return codes;
  79. }
  80. }
  81. }