- 积分
- 1386
- 明经币
- 个
- 注册时间
- 2023-2-2
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 箭头_Row 于 2024-2-18 05:36 编辑
命令描述:關於選擇封閉空間后等分命令。
命令步驟:
步驟一:選擇封閉。
步驟二:選擇分割分式。
備註:下述代碼使用了IFox庫。
源碼如下:
- namespace ArrowTools;
- public class DivisionEX : SettingsClass
- {
- public enum FirstKeywords
- {
- [Description("S")]
- 选取 = 1,
- [Desic virtual string JsonFile() => Path.GetDirectoryName(GetAssemblyPath(true)) + "\\Settings\\";
- public virtual string JsonFile() => Path.GetDirectoryName(ArrowTool.GetAssemblyPath(true)) + $"\\Settings\\{this.GetType().Name}_Settings.json";
- public virtual string JsonString() => JsonConvert.SerializeObject(this, Formatting.Indented);
- public virtual void JsonSaveAs() => File.WriteAllText(JsonFile(), JsonString());
- pubcription("R")]
- 两点 = 2,
- }
- public enum Keywords
- {
- [Description("V")]
- 垂直 = 1,
- [Description("H")]
- 水平 = 2,
- [Description("C")]
- 图层 = 4,
- [Description("N")]
- 数量 = 16,
- [Description("J")]
- 定距 = 8,
- [Description("S")]
- 定数,
- [Description("T")]
- 板厚 = 64,
- [Description("D")]
- 距离,
- [Description("Z")]
- 中心 = 32,
- [Description("A")]
- 中有分点,
- [Description("X")]
- 双线,
- [Description("+")]
- 加,
- [Description("-")]
- 减,
- [Description("1")]
- 加1,
- [Description("2")]
- 减1,
- [Description("W")]
- 加一,
- [Description("E")]
- 减一
- }
- public override string ToString() => JsonString();
- public void PrintKeywordsSettings() =>
- Env.Print($"\n图层:{DivEXLayer} 备注:定数模式下 “1”、“2”、“+”、“-”、“W”、“E” 可加减分段数!" +
- $"\n分割:{DivStyle.GetEnumByDescription<Keywords>()} 双线:{(isDoubleLine ? "是" : "否")} 距离:{distension} 数量:{number} " +
- $"\n垂线:{(VerticalDivStyle ? "垂直" : "水平")} 中心:{(isCenterDivision ? "是" : "否")} 中心有线:{(centerHasLine ? "是" : "否")} 板厚:{thickness} ");
- private static string GetEntityOptionsMessage()
- {
- return "\n点取闭合空间或 [选取(S)/两点(R)] ";
- }
- private string GetOptionsMessage(Line line)
- {
- string msg;
- if (DivStyle == Keywords.定数.GetDesc() && isDoubleLine)
- msg = $"计算结果: \n{DivStyle.GetEnumByDescription<Keywords>()}({Keywords.定数.GetDesc()}) = {Math.Round((line.Length - thickness * (number - 1)) / number, 2)} \n数量({Keywords.数量.GetDesc()}) = {number} ({Keywords.加一.GetDesc()}/{Keywords.减一.GetDesc()})\n双线({Keywords.双线.GetDesc()}) = {(isDoubleLine ? "是" : "否")} \n板厚({Keywords.板厚.GetDesc()}) = {thickness}";
- else if (DivStyle == Keywords.定数.GetDesc() && !isDoubleLine)
- msg = $"计算结果: \n{DivStyle.GetEnumByDescription<Keywords>()}({Keywords.定数.GetDesc()}) = {Math.Round(line.Length / number, 2)} \n数量({Keywords.数量.GetDesc()}) = {number} ({Keywords.加一.GetDesc()}/{Keywords.减一.GetDesc()})\n双线({Keywords.双线.GetDesc()}) = {(isDoubleLine ? "是" : "否")} ";
- else if (DivStyle == Keywords.定距.GetDesc() && isDoubleLine)
- msg = $"计算结果: \n{DivStyle.GetEnumByDescription<Keywords>()}({Keywords.定数.GetDesc()}) = {distension} {Keywords.距离}({Keywords.距离.GetDesc()}) \n数量(!) = {Math.Floor(line.Length / (distension + thickness))} \n双线({Keywords.双线.GetDesc()}) = {(isDoubleLine ? "是" : "否")} 板厚({Keywords.板厚.GetDesc()}) = {thickness} \n中心({Keywords.中心.GetDesc()}) = {(isCenterDivision ? "是" : "否")} \n中心有线({Keywords.中有分点.GetDesc()}) = {(centerHasLine ? "是" : "否")}";
- else
- msg = $"计算结果: \n{DivStyle.GetEnumByDescription<Keywords>()}({Keywords.定数.GetDesc()}) = {distension} {Keywords.距离}({Keywords.距离.GetDesc()}) \n数量(!) = {Math.Floor(line.Length / distension)} \n双线({Keywords.双线.GetDesc()}) = {(isDoubleLine ? "是" : "否")} \n中心({Keywords.中心.GetDesc()}) = {(isCenterDivision ? "是" : "否")} \n中心有线({Keywords.中有分点.GetDesc()}) = {(centerHasLine ? "是" : "否")}";
- return msg;
- }
- public override void ResetLayer()
- {
- DivEXLayer = Layers.EL_30_Name;
- divEXLayerColor = Layers.EL_30_Color;
- }
- // 2024-2-7 注意:未實例化的類中標識符 public 將序列化,pravite 不會序列化類;
- // 分割方式:定數 or 垂直
- public string DivStyle { get; set; } = Keywords.定数.GetDesc();
- public bool VerticalDivStyle = false;
- // 圖層默認設置
- public string? DivEXLayer { get; set; }
- public short divEXLayerColor;
- // 2024-2-8:"字段"是直接访问的变量,效率更高,只get无set。
- // 2024-2-8:直接賦值{ get; }=方式值是固定死的,必須使用委託方式寫才會每次都獲取新值。
- static string DivEXHsLayer => HsLayer(HesiStatusBridge.PboCAD.GetLayerStatus(), "18Norm");
- // 分割偏移 bool 設置
- public bool isDoubleLine = true;
- public bool isCenterDivision = true;
- public bool centerHasLine = true;
- // 分割偏移其它值設置
- public int number = 4;
- public double distension = 100;
- public double thickness = 10;
- [CommandMethod(nameof(CzE_Division_EX))]
- public void CzE_Division_EX()
- {
- InitLayersSettings(this);
- if (this.DivEXLayer == null)
- return;
- bool selectMode = false;
- bool twoPointMode = false;
- Polyline pline = new();
- PromptPointOptions entOpts = new("");
- List<string> myFirstKeywords = CzEnumEx.GetDescriptionList(typeof(FirstKeywords));
- entOpts.AddKeywords(myFirstKeywords);
- entOpts.AppendKeywordsToMessage = false;//不将关键字列表添加到提示信息中
- entOpts.Message = GetEntityOptionsMessage();
- entOpts.AllowNone = true;
- PromptPointResult ppr = Env.Editor.GetPoint(entOpts);
- if (ppr.Status == PromptStatus.OK)
- {
- // 获取Boundary 注意TraceBoundary 中 deleteisland 的设置
- using DBObjectCollection dbo = Env.Editor.TraceBoundary(ppr.Value, false);
- if (dbo.Count != 1)
- {
- Env.Print("\n闭合空间错误,调整后重试!");
- return;
- }
- pline = (Polyline)dbo[0];
- if (pline.NumberOfVertices == 0)
- {
- Env.Print("\n闭合空间错误,调整后重试!");
- return;
- }
- }
- using DBTrans tr = new();
- if (ppr.Status == PromptStatus.Keyword)
- {
- switch (ppr.StringResult.ToUpper().GetEnumByDescription<FirstKeywords>())
- {
- case FirstKeywords.选取:
- selectMode = true;
- while (selectMode)
- {
- var templine = GetClosedPolyline(tr);
- if (templine == null)
- return;
- if (templine.NumberOfVertices > 2)
- {
- pline = templine;
- selectMode = false;
- }
- }
- break;
- case FirstKeywords.两点:
- var templine2 = tr.TwoPointDrawRectangle();
- if (templine2 == null) return;
- pline = templine2;
- twoPointMode = true;
- break;
- }
- }
- if (ppr.Status == PromptStatus.Cancel)
- {
- Env.Print("\n命令取消!");
- return;
- }
- // 记录正交状态,命令結束或取消時還原
- bool ortho = Env.OrthoMode;
- if (Env.OrthoMode)
- Env.OrthoMode = false;
- List<Line> lines = [];
- // 创建瞬态容器
- using JigExTransient jet = new();
- // 亮显模式加到瞬态容器,即在图纸上显示
- if (pline.NumberOfVertices > 0)
- {
- // 如果是选取模式,须打开实体可读模式,否则报可写错误
- var color = pline.Color;
- if (!pline.IsWriteEnabled)
- using (pline.ForWrite())
- pline.ColorIndex = 1;
- else
- pline.ColorIndex = 1;
- jet.Add(pline, Acgi.TransientDrawingMode.Highlight);
- pline.Color = color;
- // 两点绘制模式时,瞬态显示后删除两点绘制的矩形,
- // 因为TwoPointDrawRectangle()内加了瞬态,不加入数据库会报可写错误。
- if (twoPointMode)
- pline.Erase();
- }
- PrintKeywordsSettings();
- JigPromptPointOptions? options = null;
- using var jig = new JigEx((mousePtWorld, drawEntitys) => {
- var tempVect = VerticalDivStyle ? Vector3d.YAxis.Ucs2Wcs() : Vector3d.XAxis.Ucs2Wcs();
- lines = mousePtWorld.GetIntersectLine(tempVect, pline);
- if (lines.Count != 1)
- return;
- using Line line = lines[0];
- lines = [];
- List<Point3d> listPoints = [];
- if (DivStyle == Keywords.定数.GetDesc())
- {
- for (int i = 1; i < number; i++)
- {
- if (!isDoubleLine)
- {
- double myDis = line.Length / number;
- AddDivisionPoints(line, listPoints, myDis * i);
- }
- else
- {
- if (thickness * (number - 1) > line.Length)
- {
- Env.Print("\n板厚设置错误!配置重置请联系 QQ:119 110 1855!");
- return;
- }
- double myDis = (line.Length - thickness * (number - 1)) / number;
- AddDivisionPoints(line, listPoints, (myDis * i + thickness * (i - 1)));
- AddDivisionPoints(line, listPoints, (myDis * i + thickness * i));
- }
- }
- }
- else
- {
- if (!isCenterDivision)
- {
- // 判断线的方向,在定距情况下很重要
- if (line.StartPoint.DistanceTo(mousePtWorld) > line.EndPoint.DistanceTo(mousePtWorld))
- line.ReverseCurve();
- if (!isDoubleLine)
- {
- if (distension > line.Length)
- {
- Env.Print("/n距离设置错误!");
- return;
- }
- for (int i = 1; i < line.Length / distension; i++)
- AddDivisionPoints(line, listPoints, (distension * i));
- }
- else
- {
- if (distension + thickness > line.Length)
- {
- Env.Print("/n距离设置错误!");
- return;
- }
- for (int i = 1; i < line.Length / (distension + thickness); i++)
- {
- AddDivisionPoints(line, listPoints, (distension * i + thickness * (i - 1)));
- AddDivisionPoints(line, listPoints, (distension * i + thickness * i));
- }
- // 添加最后一段如果分割距离大于定距但小于定距+板厚的情况
- if (line.Length % (distension + thickness) > distension)
- AddDivisionPoints(line, listPoints, (line.Length - (line.Length % (distension + thickness) - distension)));
- }
- }
- else
- {
- if (!isDoubleLine)
- {
- //// 2024-2-6:因設置后後續無法切換奇偶數,故取消自動判斷如何合理等分,等分數奇數 or 偶數。
- //if (line.Length % distension > distension / 2)
- // centerHasLine = true;
- //else
- // centerHasLine = false;
- if (distension > line.Length)
- {
- Env.Print("\n距离设置错误!配置重置请联系 QQ:119 110 1855!");
- return;
- }
- if (centerHasLine)
- for (int i = -(int)Math.Floor((line.Length / 2) / distension); i <= (int)Math.Floor((line.Length / 2) / distension); i++)
- AddDivisionPoints(line, listPoints, (distension * i + line.Length / 2));
- else
- for (int i = -(int)Math.Floor((line.Length - distension) / 2 / distension); i <= (int)Math.Floor((line.Length - distension) / 2 / distension) + 1; i++)
- AddDivisionPoints(line, listPoints, (distension * i + line.Length / 2 - distension / 2));
- }
- else
- {
- if (distension + thickness > line.Length)
- {
- Env.Print("\n距离设置错误!配置重置请联系 QQ:119 110 1855!");
- return;
- }
- if (centerHasLine)
- {
- for (int i = -(int)Math.Floor((line.Length / 2) / (distension + thickness)); i <= (int)Math.Floor((line.Length / 2) / (distension + thickness)); i++)
- {
- AddDivisionPoints(line, listPoints, (distension * i + thickness * (i - 1) + line.Length / 2 + thickness / 2));
- AddDivisionPoints(line, listPoints, (distension * i + thickness * i + line.Length / 2 + thickness / 2));
- }
- }
- else
- {
- for (int i = -(int)Math.Floor(((line.Length - distension) / 2) / (distension + thickness)) - 1; i <= (int)Math.Floor(((line.Length - distension) / 2) / (distension + thickness)); i++)
- {
- AddDivisionPoints(line, listPoints, (distension * i + thickness * i + line.Length / 2 + distension / 2));
- AddDivisionPoints(line, listPoints, (distension * i + thickness * (i + 1) + line.Length / 2 + distension / 2));
- }
- ////添加最后一段如果分割距离大于定距但小于定距 + 板厚的情况
- //if ((line.Length - distension) % (distension + thickness) > 0)
- //{
- // AddDivisionPoints(line, listPoints, ((line.Length - distension) % (distension + thickness) / 2));
- // AddDivisionPoints(line, listPoints, (line.Length - ((line.Length - distension) % (distension + thickness) / 2)));
- //}
- }
- }
- }
- }
- // 生成等分线
- var vector = VerticalDivStyle ? Vector3d.XAxis.Ucs2Wcs() : Vector3d.YAxis.Ucs2Wcs();
- foreach (var newPoint in listPoints)
- foreach (Line lineIst in newPoint.GetIntersectLine(vector, pline))
- lines.Add(lineIst);
- if (lines.Count > 0)
- foreach (Line ent in lines)
- {
- if (DivEXLayer == "当前")
- ent.SetDatabaseDefaults();
- else
- ent.SetProperty(DivEXHsLayer, DivEXLayer, divEXLayerColor);
- drawEntitys.Enqueue(ent); // 加入刷新队列
- }
- options!.Message = GetOptionsMessage(line);
- });
- options = jig.SetOptions(ppr.Value, CursorType.EntitySelect, "\n选择点或 [竖直\\水平(V\\H)/图层(C)/定数\\定距(S\\J)/数量(N)/距离(D)/板厚(T)/中心(Z)/中心有线(A)/双线(X)] ");
- options.AppendKeywordsToMessage = false; //不将关键字列表添加到提示信息中
- List<string> myKeywords = CzEnumEx.GetDescriptionList(typeof(Keywords));
- options.AddKeywords(myKeywords);
- options.UseBasePoint = false;
- bool jigDragFlag = true;
- while (jigDragFlag)
- {
- var pr = jig.Drag();
- if (pr.Status == PromptStatus.Keyword)
- {
- switch (pr.StringResult.ToUpper().GetEnumByDescription<Keywords>())
- {
- case Keywords.垂直 or Keywords.水平:
- VerticalDivStyle = !VerticalDivStyle;
- break;
- case Keywords.定数 or Keywords.定距:
- if (DivStyle == Keywords.定数.GetDesc())
- DivStyle = Keywords.定距.GetDesc();
- else
- DivStyle = Keywords.定数.GetDesc();
- break;
- case Keywords.图层:
- string? layerName = tr.GetEntityLayer();
- if (layerName != null)
- DivEXLayer = layerName;
- if (layerName == "重置")
- ResetLayer(); //重置圖層
- break;
- case Keywords.数量:
- PromptIntegerOptions pio = new("输入数量")
- {
- LowerLimit = 2,
- UpperLimit = 100,
- DefaultValue = number
- };
- PromptIntegerResult pir = Env.Editor.GetInteger(pio);
- if (pir.Status == PromptStatus.OK)
- number = pir.Value;
- else
- Env.Print("输入错误!");
- break;
- case Keywords.距离:
- PromptDistanceOptions pdo = new("\n选择距离");
- pdo.DefaultValue = distension;
- PromptDoubleResult pdr = Env.Editor.GetDistance(pdo);
- if (pdr.Status == PromptStatus.OK)
- distension = Math.Round(pdr.Value, 2);
- break;
- case Keywords.板厚:
- thickness = BoardOffset.GetBoardThickness("\n点选板厚(或手动输入):", thickness);
- break;
- case Keywords.中心:
- isCenterDivision = !isCenterDivision;
- break;
- case Keywords.中有分点:
- centerHasLine = !centerHasLine;
- break;
- case Keywords.双线:
- isDoubleLine = !isDoubleLine;
- break;
- case Keywords.加 or Keywords.加1 or Keywords.加一:
- number += 1;
- break;
- case Keywords.减 or Keywords.减1 or Keywords.减一:
- if (number > 2)
- number -= 1;
- break;
- }
- //序列化*类转字符串
- JsonSaveAs();
- PrintKeywordsSettings();
- }
- else if (pr.Status == PromptStatus.OK || pr.Status == PromptStatus.None)
- {
- //剔除未生成Line,还是初始化状态的情况
- if (jig.Entitys.Length <= 0)
- Env.Editor.WriteMessage("\n点超出边界,调整后重试!");
- else
- foreach (var entity in jig.Entitys)
- if (entity is Line)
- tr.CurrentSpace.AddEntity(entity);
- // 還原正交状态 and 點樣式
- Env.OrthoMode = ortho;
- jigDragFlag = false;
- }
- else
- { // 還原正交状态 and 點樣式
- Env.OrthoMode = ortho;
- Env.Print("\n命令取消!");
- return;
- }
- }
- }
- /// </summary>
- /// 给定的分割线(Line)在指定距离(double)上添加分割点(Point3d)
- /// </summary>
- /// <param name="divisionLine">要添加分割點的分割線</param>
- /// <param name="divisionPoints">用於保存分割點的列表</param>
- /// <param name="distension">分割點與起點之間的距離</param>
- private static void AddDivisionPoints(Line divisionLine, List<Point3d> divisionPoints, double distension)
- {
- //获取距离起点 mydis 的多段线上的一个点
- Point3d point = divisionLine.GetPointAtDist(distension);
- //一阶导数 即切线向量
- Vector3d curVector = divisionLine.GetFirstDerivative(point);
- //获取切线方向的垂线向量的标准单位向量 (从切线得到法线)
- Vector3d curPervector = curVector.GetPerpendicularVector().GetNormal();
- //起始点+ 单位向量*距离 就是距离起始点 距离向量长度的 一个点
- Point3d newPoint = point + curPervector * distension;
- divisionPoints.Add(newPoint);
- }
- }
另一個C#文件名:SettingsClass.cs
關於初始化設置!!!!
- namespace ArrowTools;
- public interface IInitSettins
- {
- /// <summary>
- /// json文件:带文件名及后缀。
- /// </summary>
- /// <returns>完整文件名路徑 + 名稱</returns>
- public string JsonFile();
- /// <summary>
- /// 序列化類
- /// </summary>
- /// <returns>序列化string</returns>
- public string JsonString();
- /// <summary>
- /// 保存序列化類至配置文件。
- /// </summary>
- public void JsonSaveAs();
- /// <summary>
- /// 反序列化類
- /// </summary>
- /// <typeparam name="T">類名</typeparam>
- /// <returns>配置轉類</returns>
- public T JsonToType<T>();
- /// <summary>
- /// 圖層重置
- /// </summary>
- public void ResetLayer();
- }
- public class SettingsClass : IInitSettins
- {
- public virtual void ResetLayer()
- {
- }
- //public virtual string JsonFile() => Path.GetDirectoryName(GetAssemblyPath(true)) + "\\Settings\\";
- public virtual string JsonFile() => Path.GetDirectoryName(ArrowTool.GetAssemblyPath(true)) + $"\\Settings\\{this.GetType().Name}_Settings.json";
- public virtual string JsonString() => JsonConvert.SerializeObject(this, Formatting.Indented);
- public virtual void JsonSaveAs() => File.WriteAllText(JsonFile(), JsonString());
- public T JsonToType<T>() => JsonConvert.DeserializeObject<T>(File.ReadAllText(JsonFile()))!;
- }
關於接口文件:SettingsTools.cs
- namespace ArrowTools;
- public static class SettingsTools
- {
- /// <summary>
- /// 初始化圖層配置:檢查配置路徑。
- /// </summary>
- public static void InitLayersSettings<T>(T thisType) where T : class, IInitSettins
- {
- var path = thisType.JsonFile();
- string dirName = Path.GetDirectoryName(path)!; // 获取指定路径文件所在的文件夹的名称
- if (!Directory.Exists(dirName))
- Directory.CreateDirectory(dirName); // 在指定的路径下创建一个新的文件夹。
- if (!File.Exists(path))
- {
- thisType.ResetLayer();
- thisType.JsonSaveAs();
- //File.WriteAllText(path, thisType.JsonString());
- }
- // 反序列化后映射類
- T jsonType = thisType.JsonToType<T>();
- ReflectSlef(jsonType, thisType);
- }
- public static void ReflectSlef<T>(T jsonType, T thisType) where T : class
- {
- Dictionary<string, object> dic = [];
- // 获取 jsonType 的所有属性和字段:注意!!!!要加上(BindingFlags.Instance)這個形參!
- Type temptype = jsonType.GetType();
- Type thistype = thisType.GetType();
- PropertyInfo[] tempPpt = temptype.GetProperties(BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance);
- PropertyInfo[] thisPpt = thistype.GetProperties(BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance);
- FieldInfo[] tempFI = temptype.GetFields(BindingFlags.Public | BindingFlags.SetField | BindingFlags.Instance);
- FieldInfo[] thisFI = thistype.GetFields(BindingFlags.Public | BindingFlags.SetField | BindingFlags.Instance);
- // 遍历属性、字段并输出属性名和值,2024-2-10:注意過濾條件應為可寫、非私有變量。
- for (int i = 0; i < tempPpt.Length; i++)
- if (tempPpt.PropertyType.IsPublic && thisPpt.CanWrite)
- dic.Add(tempPpt.Name, tempPpt.GetValue(jsonType));
- for (int i = 0; i < tempFI.Length; i++)
- if (thisFI.IsPublic)
- dic.Add(tempFI.Name, tempFI.GetValue(jsonType));
- for (int i = 0; i < thisPpt.Length; i++)
- if (tempPpt.PropertyType.IsPublic && thisPpt.CanWrite)
- thisPpt.SetValue(thisType, dic[thisPpt.Name]); // 设置属性值
- for (int i = 0; i < thisFI.Length; i++)
- if (thisFI.IsPublic)
- thisFI.SetValue(thisType, dic[thisFI.Name]); // 设置字段值
- }
- [MyMethod]
- public static void ReflectSlefFuntion<T>(T thisType) where T : class
- {
- Dictionary<string, object> dic = [];
- // 获取 jsonType 的所有属性和字段:注意!!!!要加上(BindingFlags.Instance)這個形參!
- Type thistype = thisType.GetType();
- MethodInfo[] thisFun = thistype.GetMethods(BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance);
- for (int i = 0; i < thisFun.Length; i++)
- thisFun.Equals(dic[thisFun.Name]); // 设置功能
- }
- }
關於獲取:获取dll运行路径 and 添加關鍵字函數- /// <summary>
- /// 获取dll运行路径,并添加入注册表供lisp调用
- /// </summary>
- /// <param name="full">true是含有文件名</param>
- /// <returns>当前dll路径</returns>
- public static string GetAssemblyPath(bool full)
- {
- // 获取程序集的位置 "file:/// G:/K01.惊惊连盒/NET35/JoinBox.dll"
- string path = Assembly.GetExecutingAssembly().CodeBase;
- /*
- * 似乎直接切割比较快
- * path = path.Replace("file:/// ", string.Empty).Replace("/", "\");
- */
- var url = new UriBuilder(path);
- path = Uri.UnescapeDataString(url.Path);// 这里路径是/
- if (full)
- return Path.GetFullPath(path); // 这里是\\
- path = Path.GetDirectoryName(path);// 这里是\\
- var it = path.LastIndexOf('\\');
- if (it != -1)
- path = path[..it] + "\"; // 返回上一级目录
- return path;
- }
- /// <summary>
- /// 添加关键字至设置中
- /// </summary>
- /// <param name="options">PromptOptions设置</param>
- /// <param name="keywords">关键字</param>
- public static void AddKeywords(this PromptPointOptions options, List<string> Keywords)
- {
- foreach (var key in Keywords)
- {
- if (!options.Keywords.Contains(key))
- options.Keywords.Add(key);
- }
- }
- /// <summary>
- /// 添加关键字至设置中
- /// </summary>
- /// <param name="options">PromptOptions设置</param>
- /// <param name="keywords">关键字</param>
- public static void AddKeywords(this PromptEntityOptions options, List<string> Keywords)
- {
- foreach (var key in Keywords)
- {
- if (!options.Keywords.Contains(key))
- options.Keywords.Add(key);
- }
- }
- /// <summary>
- /// 添加关键字至设置中
- /// </summary>
- /// <param name="options">jig设置</param>
- /// <param name="keywords">关键字</param>
- public static void AddKeywords(this JigPromptPointOptions? options, IEnumerable<string> keywords)
- {
- foreach (var key in keywords)
- {
- if (!options!.Keywords.Contains(key))
- options.Keywords.Add(key);
- }
- }
复制代码
- /// <summary>
- /// 获取枚举类型的所有描述项。
- /// </summary>
- /// <param name="enumType">枚举类型</param>
- /// <returns>返回描述项</returns>
- public static List<string> GetDescriptionList(Type enumType)
- {
- List<string> nameList = [];
- foreach (var e in Enum.GetValues(enumType))
- {
- // 转换成Description后添加至List
- object objArr = e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true)[0];
- nameList.Add(((DescriptionAttribute)objArr).Description);
- }
- return nameList;
- }
備註: 感謝驚驚大佬的關於如何序列化的指教!!!!
感謝IFOX源碼共享,另此命令參照源泉設計的DF命令設計製作,感謝源泉作者無私分享插件!!!!
上圖中若缺失函數可反饋后修改,上圖中函數可能會有部份源碼在項目的其它文件夾中,未作具體驗證,可回帖后上傳源碼!
|
|