SharedParameterDefinition.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:SharedParameterDefinition
  3. * 作者:xulisong
  4. * 创建时间: 2019/3/7 11:14:57
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Autodesk.Revit.ApplicationServices;
  13. using Autodesk.Revit.DB;
  14. namespace FWindSoft.Revit
  15. {
  16. public class SharedParameterDefinition
  17. {
  18. public const string DefualtGroupName = "共享参数";
  19. public SharedParameterDefinition():this(DefualtGroupName)
  20. {
  21. }
  22. public SharedParameterDefinition(string groupName)
  23. {
  24. GroupName = groupName?? DefualtGroupName;
  25. ParameterType = ParameterType.Text;
  26. }
  27. public string GroupName { get; private set; }
  28. public string Name { get; set; }
  29. public ParameterType ParameterType { get; set; }
  30. public bool IsVisible { get; set; } = true;
  31. public bool UserModify { get; set; } = true;
  32. /// <summary>
  33. /// 获取参数定义
  34. /// </summary>
  35. /// <param name="application"></param>
  36. /// <returns></returns>
  37. public Definition GetDifinition(Application application)
  38. {
  39. var file= SharedParameterUtil.GetSharedParameterFile(application);
  40. var group = file.Groups.get_Item(GroupName);
  41. if (null == group)
  42. {
  43. group = file.Groups.Create(GroupName);
  44. }
  45. if (group == null)
  46. throw new Exception("查找参数分组失败");
  47. Definition definition = group.Definitions.get_Item(Name);
  48. if (definition == null)
  49. {
  50. var options = SharedParameterUtil.NewDefinitionCreationOptions(Name, ParameterType, true, true);
  51. definition = SharedParameterUtil.NewDefinition(group,options);
  52. }
  53. return definition;
  54. }
  55. }
  56. }