SharedParameterExtension.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:SharedParameterExtension
  3. * 作者:xulisong
  4. * 创建时间: 2019/3/7 13:18:15
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using Autodesk.Revit.DB;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace FWindSoft.Revit
  14. {
  15. public static class SharedParameterExtension
  16. {
  17. /// <summary>
  18. /// 设置共享参数,没有的话进行自动创建
  19. /// </summary>
  20. /// <param name="element"></param>
  21. /// <param name="key"></param>
  22. /// <param name="value"></param>
  23. /// <returns></returns>
  24. public static bool SetSharedParameter(this Element element, string key, string value)
  25. {
  26. if (!element.ExistParameter(key))
  27. {
  28. SharedParameterDefinition definiton = new SharedParameterDefinition();
  29. definiton.Name = key;
  30. var bindingType = element is ElementType;
  31. var flag= SharedParameterUtil.BindingParameter(element.Document,element.Category, bindingType, definiton.GetDifinition(element.Document.Application));
  32. if (!flag)
  33. {
  34. //绑定参数未成功
  35. return flag;
  36. }
  37. }
  38. return element.SetParameter(key, value);
  39. }
  40. }
  41. }