当前位置: 首页 > wzjs >正文

数据统计网站电子商务网站建设参考文献书籍

数据统计网站,电子商务网站建设参考文献书籍,制作书签的感受心得,seo是怎么优化的配置文件的读取 在AutoCAD插件开发中,可能需要生成、修改、读取配置文件中一些参数或设置。JSON格式的配置文件易于编写和修改,且可以方便地反序列化为对象进行使用。 运行后效果如下 using Autodesk.AutoCAD.ApplicationServices; using Autodesk.Au…

配置文件的读取

在AutoCAD插件开发中,可能需要生成、修改、读取配置文件中一些参数或设置。JSON格式的配置文件易于编写和修改,且可以方便地反序列化为对象进行使用。

运行后效果如下

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Newtonsoft.Json;
using System;
using System.IO;
using Path = System.IO.Path;
// AutoCAD 命令示例
public class ConfigCommands
{[CommandMethod("xx")]public void 加载文件配置(){Document doc = Application.DocumentManager.MdiActiveDocument;Editor ed = doc.Editor;// 加载配置AppConfig config = ConfigManager.LoadConfig();// 应用配置到图纸ConfigManager.ApplyConfigToDrawing(config);ed.WriteMessage($"\n已加载配置:默认图层 {config.DefaultLayer}");}[CommandMethod("tt")]public void 修改文件配置(){Document doc = Application.DocumentManager.MdiActiveDocument;Editor ed = doc.Editor;// 获取当前配置AppConfig config = ConfigManager.LoadConfig();// 修改配置示例config.DefaultLayer = "MyNewLayer";config.DefaultLineWeight = 0.5;// 保存配置ConfigManager.SaveConfig(config);ed.WriteMessage("\n配置已更新并保存");}
}
// 配置文件数据结构(示例)
public class AppConfig
{public string DefaultLayer { get; set; } = "0";      // 默认图层public double DefaultLineWeight { get; set; } = 0.3; // 默认线宽(毫米)public string[] RecentFiles { get; set; }            // 最近打开文件记录public ColorSetting Colors { get; set; }             // 颜色配置
}public class ColorSetting
{public int Background { get; set; } = 16777215;     // 背景色(RGB白色)public int SelectionHighlight { get; set; } = 255;   // 选择高亮色(红色)
}public static class ConfigManager
{private static readonly string ConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"MyAutoCADPlugin","config.json");/// <summary>/// 加载配置文件/// </summary>public static AppConfig LoadConfig(){try{// 如果配置文件不存在,创建默认配置if (!File.Exists(ConfigPath)){var defaultConfig = new AppConfig();SaveConfig(defaultConfig);return defaultConfig;}// 读取并反序列化JSONstring json = File.ReadAllText(ConfigPath);return JsonConvert.DeserializeObject<AppConfig>(json);}catch (Exception ex){Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\n配置加载失败: {ex.Message}");return new AppConfig(); // 返回空配置}}/// <summary>/// 保存配置文件/// </summary>public static void SaveConfig(AppConfig config){try{// 确保目录存在Directory.CreateDirectory(Path.GetDirectoryName(ConfigPath));// 序列化并保存string json = JsonConvert.SerializeObject(config, Formatting.Indented);File.WriteAllText(ConfigPath, json);}catch (Exception ex){Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\n配置保存失败: {ex.Message}");}}/// <summary>/// 应用配置到当前图纸/// </summary>public static void ApplyConfigToDrawing(AppConfig config){Database db = HostApplicationServices.WorkingDatabase;using (Transaction tr = db.TransactionManager.StartTransaction()){try{// 获取层表LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;// 检查默认图层是否存在if (!lt.Has(config.DefaultLayer)){// 创建新图层LayerTableRecord ltr = new LayerTableRecord{Name = config.DefaultLayer,LineWeight = LineWeight.LineWeight030};lt.UpgradeOpen();lt.Add(ltr);tr.AddNewlyCreatedDBObject(ltr, true);}// 设置当前图层db.Clayer = lt[config.DefaultLayer];tr.Commit();}catch (Exception ex){tr.Abort();Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\n配置应用失败: {ex.Message}");}}}
}

http://www.dtcms.com/wzjs/822007.html

相关文章:

  • 帮网站做推广赚钱吗医疗网站建设代理商
  • 服装网站建设项目规划天河区建网站
  • 石碣镇网站仿做网页qq登录保护不再开启入口
  • 新网站建设市场深圳网站备案时间
  • 做网站公司找哪家公司租号网站开发成本
  • 网站费用明细朋友圈信息流广告投放价格
  • 免费企业网站模板成都高投建设开发有限公司网站
  • 高端网站建设公司排行网站建设与管理课程总结
  • 单纯做seo能否提升网站流量建设银行wap网站
  • 沈阳市城乡建设局网站设计师的职责
  • 公众号做视频网站wordpress文件wordpress
  • WordPress创建的网站爱奇艺号自媒体平台注册
  • 做网站一般图片的比例百度一下首页
  • 加快政务公开网站建设怎么提高网站排名
  • 电商网站开发设计方法是在百度中建设网站
  • 网站建设有哪些荣誉福州网站建设需要多少钱
  • 2345网址导航官网下载安装关键词营销优化
  • 网站建设最常见的问题织梦网络公司网站
  • 北京专业网站设计推荐用vs2012做网站案例
  • 网站做关键词排名有必要吗网站维护工作内容
  • 东莞公司想建网站科技有限公司可以做网站建设吗?
  • 山东机关建设网站怎么给一个花店做网站建设
  • 个人 可以做网站备案吗做视频采集网站违法吗
  • 网站建设按什么合同交印花税有用dojo做的网站吗
  • 大学代作作业的网站做公众号要不要有自己的网站
  • 开发网站去哪里学wordpress浏览pdf
  • 从化营销网站建设在线培训平台有哪些
  • 建设行政管理部门网站怎们自己做网站
  • 网站架设软件没有有知道钓鱼网站在哪儿做
  • 教你做美食的网站家在深圳 业主论坛