123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- /* ==============================================================================
- * 功能描述:CommonTool
- * 创 建 者:Garrett
- * 创建日期:2018/3/13 17:26:29
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using Autodesk.Revit.DB;
- using Newtonsoft.Json.Linq;
- using SAGA.DotNetUtils.Extend;
- namespace MBIUtility.Tool
- {
- /// <summary>
- /// CommonTool
- /// </summary>
- public class CommonTool
- {
-
- /// <summary>
- /// 获取楼层顺序号
- /// </summary>
- /// <param name="cur">当前顺序号</param>
- /// <param name="seed">上面增加(1)下面增加是(-1)</param>
- /// <returns></returns>
- public static int GetNewSequence(int cur, int seed)
- {
- if (seed == -1)
- {
- cur = cur < 0 ? cur + seed : cur;
- }
- else
- {
- cur = cur < 0 ? cur : cur + seed;
- }
- return cur;
- }
- /// <summary>
- /// 获取楼层顺序号
- /// </summary>
- /// <param name="cur">当前顺序号</param>
- /// <param name="seed">上面增加(1)下面增加是(-1)</param>
- /// <returns></returns>
- public static int GetNextSequence(int cur)
- {
- cur = cur > 0 ? cur + 1 : cur - 1;
- return cur;
- }
- /// <summary>
- /// 由楼层顺序号获取生成revit文件的文件名称;
- /// 默认为B1,B2,F1,F2...
- /// </summary>
- /// <param name="sequence"></param>
- /// <returns></returns>
- public static string GetFloorRevitFileName(int sequence)
- {
- if (sequence > 0)
- return "F" + sequence;
- else
- {
- return "B" + Math.Abs(sequence);
- }
- }
- /// <summary>
- /// 信息点置为null
- /// </summary>
- public readonly static string NullStr="Nlul";
- public static JArray GetPropertyJArray(string value)
- {
- JArray jArray = new JArray();
- if (value == null)
- return jArray;
- JObject valueJObject = new JObject();
- if (value.Equals(NullStr))
- {
- valueJObject.Add("value", null);
- }
- else
- {
- valueJObject.Add("value", value);
- }
- jArray.Add(valueJObject);
- return jArray;
- }
- /// <summary>
- /// 获取信息点更新是传递的数据结构
- /// </summary>
- /// <param name="code"></param>
- /// <param name="value"></param>
- /// <returns></returns>
- public static JObject GetPropertyJObject(string code,string value)
- {
- #region 构建array
- JArray jArray = new JArray();
- JObject valueJObject = new JObject();
- valueJObject.Add("value", value);
- jArray.Add(valueJObject);
- #endregion
- JObject jObject = new JObject();
- jObject.Add(code, jArray);
- return jObject;
- }
- public static JArray GetPropertyJArray(string time, string value)
- {
- JArray jArray = new JArray();
- JObject valueJObject = new JObject();
- valueJObject.Add("time", time);
- valueJObject.Add("value", value);
- jArray.Add(valueJObject);
- return jArray;
- }
- public static JArray GetPropertyJArray(JToken value)
- {
- JArray jArray = new JArray();
- JObject valueJObject = new JObject();
- valueJObject.Add("value", value);
- jArray.Add(valueJObject);
- return jArray;
- }
- /// <summary>
- /// 由文件的全路径获取云端文件名
- /// </summary>
- /// <param name="path"></param>
- /// <returns></returns>
- public static string GetCloudRevitName(string path)
- {
- var strs = path.Split('\\', ':');
- List<string> last3Strs = new List<string>();
- for (int i = strs.Length - 3; i < strs.Length; i++)
- {
- last3Strs.Add(strs[i]);
- }
- string fileName = string.Join("_", last3Strs.ToArray());
- return fileName;
- }
- /// <summary>
- /// 将点按 “;”进行分组
- /// </summary>
- /// <param name="xyzs"></param>
- /// <returns></returns>
- public static string ConvertSpaceEdgesToStr(List<XYZ> xyzs)
- {
- var strs = xyzs.Select(t => t.X + "," + t.Y);
- var str = string.Join(";", strs.ToArray());
- return str;
- }
-
- /// <summary>
- /// 创建个资产id
- /// id为Pe+uuid(去掉横线)
- /// </summary>
- /// <returns></returns>
- public static string CreateNewFmId()
- {
- string id = System.Guid.NewGuid().ToString("N");
- return "Pe" + id;
- }
- /// <summary>
- /// 获取BIMId
- /// </summary>
- /// <param name="docName"></param>
- /// <param name="id"></param>
- /// <returns></returns>
- public static string GetCloudBIMId(string docName, string id)
- {
- return $"{docName}:{id}";
- }
-
- /// <summary>
- /// 由视频预览图--获取视频的名称
- /// </summary>
- /// <param name="name"></param>
- /// <returns></returns>
- public static string GetVideoKeyByImageKey(string name)
- {
- string videoSuffix = ".mp4";
- return name.GetAppointSuffixPath(videoSuffix);
- }
-
- }
- }
|