CommonTool.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* ==============================================================================
  2. * 功能描述:CommonTool
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/3/13 17:26:29
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using Autodesk.Revit.DB;
  11. using Newtonsoft.Json.Linq;
  12. using SAGA.DotNetUtils.Extend;
  13. namespace MBIUtility.Tool
  14. {
  15. /// <summary>
  16. /// CommonTool
  17. /// </summary>
  18. public class CommonTool
  19. {
  20. /// <summary>
  21. /// 获取楼层顺序号
  22. /// </summary>
  23. /// <param name="cur">当前顺序号</param>
  24. /// <param name="seed">上面增加(1)下面增加是(-1)</param>
  25. /// <returns></returns>
  26. public static int GetNewSequence(int cur, int seed)
  27. {
  28. if (seed == -1)
  29. {
  30. cur = cur < 0 ? cur + seed : cur;
  31. }
  32. else
  33. {
  34. cur = cur < 0 ? cur : cur + seed;
  35. }
  36. return cur;
  37. }
  38. /// <summary>
  39. /// 获取楼层顺序号
  40. /// </summary>
  41. /// <param name="cur">当前顺序号</param>
  42. /// <param name="seed">上面增加(1)下面增加是(-1)</param>
  43. /// <returns></returns>
  44. public static int GetNextSequence(int cur)
  45. {
  46. cur = cur > 0 ? cur + 1 : cur - 1;
  47. return cur;
  48. }
  49. /// <summary>
  50. /// 由楼层顺序号获取生成revit文件的文件名称;
  51. /// 默认为B1,B2,F1,F2...
  52. /// </summary>
  53. /// <param name="sequence"></param>
  54. /// <returns></returns>
  55. public static string GetFloorRevitFileName(int sequence)
  56. {
  57. if (sequence > 0)
  58. return "F" + sequence;
  59. else
  60. {
  61. return "B" + Math.Abs(sequence);
  62. }
  63. }
  64. /// <summary>
  65. /// 信息点置为null
  66. /// </summary>
  67. public readonly static string NullStr="Nlul";
  68. public static JArray GetPropertyJArray(string value)
  69. {
  70. JArray jArray = new JArray();
  71. if (value == null)
  72. return jArray;
  73. JObject valueJObject = new JObject();
  74. if (value.Equals(NullStr))
  75. {
  76. valueJObject.Add("value", null);
  77. }
  78. else
  79. {
  80. valueJObject.Add("value", value);
  81. }
  82. jArray.Add(valueJObject);
  83. return jArray;
  84. }
  85. /// <summary>
  86. /// 获取信息点更新是传递的数据结构
  87. /// </summary>
  88. /// <param name="code"></param>
  89. /// <param name="value"></param>
  90. /// <returns></returns>
  91. public static JObject GetPropertyJObject(string code,string value)
  92. {
  93. #region 构建array
  94. JArray jArray = new JArray();
  95. JObject valueJObject = new JObject();
  96. valueJObject.Add("value", value);
  97. jArray.Add(valueJObject);
  98. #endregion
  99. JObject jObject = new JObject();
  100. jObject.Add(code, jArray);
  101. return jObject;
  102. }
  103. public static JArray GetPropertyJArray(string time, string value)
  104. {
  105. JArray jArray = new JArray();
  106. JObject valueJObject = new JObject();
  107. valueJObject.Add("time", time);
  108. valueJObject.Add("value", value);
  109. jArray.Add(valueJObject);
  110. return jArray;
  111. }
  112. public static JArray GetPropertyJArray(JToken value)
  113. {
  114. JArray jArray = new JArray();
  115. JObject valueJObject = new JObject();
  116. valueJObject.Add("value", value);
  117. jArray.Add(valueJObject);
  118. return jArray;
  119. }
  120. /// <summary>
  121. /// 由文件的全路径获取云端文件名
  122. /// </summary>
  123. /// <param name="path"></param>
  124. /// <returns></returns>
  125. public static string GetCloudRevitName(string path)
  126. {
  127. var strs = path.Split('\\', ':');
  128. List<string> last3Strs = new List<string>();
  129. for (int i = strs.Length - 3; i < strs.Length; i++)
  130. {
  131. last3Strs.Add(strs[i]);
  132. }
  133. string fileName = string.Join("_", last3Strs.ToArray());
  134. return fileName;
  135. }
  136. /// <summary>
  137. /// 将点按 “;”进行分组
  138. /// </summary>
  139. /// <param name="xyzs"></param>
  140. /// <returns></returns>
  141. public static string ConvertSpaceEdgesToStr(List<XYZ> xyzs)
  142. {
  143. var strs = xyzs.Select(t => t.X + "," + t.Y);
  144. var str = string.Join(";", strs.ToArray());
  145. return str;
  146. }
  147. /// <summary>
  148. /// 创建个资产id
  149. /// id为Pe+uuid(去掉横线)
  150. /// </summary>
  151. /// <returns></returns>
  152. public static string CreateNewFmId()
  153. {
  154. string id = System.Guid.NewGuid().ToString("N");
  155. return "Pe" + id;
  156. }
  157. /// <summary>
  158. /// 获取BIMId
  159. /// </summary>
  160. /// <param name="docName"></param>
  161. /// <param name="id"></param>
  162. /// <returns></returns>
  163. public static string GetCloudBIMId(string docName, string id)
  164. {
  165. return $"{docName}:{id}";
  166. }
  167. /// <summary>
  168. /// 由视频预览图--获取视频的名称
  169. /// </summary>
  170. /// <param name="name"></param>
  171. /// <returns></returns>
  172. public static string GetVideoKeyByImageKey(string name)
  173. {
  174. string videoSuffix = ".mp4";
  175. return name.GetAppointSuffixPath(videoSuffix);
  176. }
  177. }
  178. }