RevitTools.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7. using Autodesk.Revit.DB;
  8. using Autodesk.Revit.UI.Selection;
  9. namespace FWindSoft.Revit.Common
  10. {
  11. public static class RevitTools
  12. {
  13. /// <summary>
  14. /// 移除非法字符串
  15. /// </summary>
  16. /// <param name="strValue"></param>
  17. /// <returns></returns>
  18. public static string RemoveForbiddenChars(this string strValue)
  19. {
  20. if (string.IsNullOrWhiteSpace(strValue))
  21. {
  22. return strValue;
  23. }
  24. foreach (var item in RevitSetting.RvtForbiddenChars)
  25. {
  26. strValue=strValue.Replace(item, "");
  27. }
  28. return strValue;
  29. }
  30. public static int RevitLeftPoint
  31. {
  32. get
  33. {
  34. var mainRec = RevitCore.UIApp.DrawingAreaExtents;
  35. return mainRec.Left;
  36. }
  37. }
  38. public static int RevitRightPoint
  39. {
  40. get
  41. {
  42. var mainRec = RevitCore.UIApp.DrawingAreaExtents;
  43. return mainRec.Right;
  44. }
  45. }
  46. public static int RevitTopPoint
  47. {
  48. get
  49. {
  50. var mainRec = RevitCore.UIApp.MainWindowExtents;
  51. return mainRec.Top;
  52. }
  53. }
  54. public static int RevitBottomPoint
  55. {
  56. get
  57. {
  58. var mainRec = RevitCore.UIApp.DrawingAreaExtents;
  59. return mainRec.Bottom;
  60. }
  61. }
  62. /// <summary>
  63. /// 整数转rgb
  64. /// </summary>
  65. /// <param name="intColor"></param>
  66. /// <returns></returns>
  67. public static Color GetColor(int intColor)
  68. {
  69. byte b = (byte)(intColor / (256 * 256));
  70. byte g = (byte)((intColor - b * 256 * 256) / 256);
  71. byte r = (byte)(intColor - b * 256 * 256 - g * 256);
  72. return new Color(r, g, b);
  73. }
  74. /// <summary>
  75. /// rgb转整数(Revit参数使用)
  76. /// </summary>
  77. /// <param name="color"></param>
  78. /// <returns></returns>
  79. public static int GetColor(Color color)
  80. {
  81. return color.Red + color.Green * 256 + color.Blue * 256 * 256;
  82. }
  83. }
  84. }