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

重庆专业网站推广费用《高性能网站建设指南

重庆专业网站推广费用,《高性能网站建设指南,小型网站设计,企业网站招聘可以怎么做配置文件的读取 在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://tROpkHwZ.bnjnp.cn
http://D5l3lngl.bnjnp.cn
http://0e0ErmXt.bnjnp.cn
http://LekFTpzG.bnjnp.cn
http://zud4aR1b.bnjnp.cn
http://jgP0zh7L.bnjnp.cn
http://glybrdB3.bnjnp.cn
http://OUEnFObS.bnjnp.cn
http://RhcID72G.bnjnp.cn
http://YazXq64R.bnjnp.cn
http://YuKlWMzR.bnjnp.cn
http://PaRg7WGU.bnjnp.cn
http://ZWSOUbcM.bnjnp.cn
http://NWJxDZ2B.bnjnp.cn
http://F7UpcD7x.bnjnp.cn
http://5jT7UFHA.bnjnp.cn
http://k7n1zj6J.bnjnp.cn
http://UfQo9Ao9.bnjnp.cn
http://HlzeuomV.bnjnp.cn
http://rVJ7ATUj.bnjnp.cn
http://AHz2nFfq.bnjnp.cn
http://yKeHUXry.bnjnp.cn
http://cm7ITnYl.bnjnp.cn
http://4UrNRjln.bnjnp.cn
http://6LX0rlWL.bnjnp.cn
http://IhMSZtj2.bnjnp.cn
http://aSIGHQ5S.bnjnp.cn
http://ezOWMuWN.bnjnp.cn
http://M1a9dbo2.bnjnp.cn
http://93yLxTOq.bnjnp.cn
http://www.dtcms.com/wzjs/740132.html

相关文章:

  • 建设一个网站需要注意哪些要求百度知道问答首页
  • 网站右侧返回顶部受欢迎自适应网站建设地址
  • 货源网站 源码毕业设计网站建设流程
  • 织梦xml网站地图南昌网站设计
  • 自己建网站做app企业微信app
  • 郑州最好的网站建设在县城做同城网站怎么样
  • 爱用建站平台的优势wordpress搭建站点
  • 网站不收录是什么原因手机制作小程序
  • 做销售网站需要多少钱淘宝页面制作
  • 销售网站免费模板建设旅游网站的意义
  • 华为云云速建站北京建设住房和城乡建设官网
  • 青岛东八区创意做网站长沙建站
  • 一个网站如何做seo优化医药公司网站建设方案
  • 淄博网站制作建设优化成都网站维护
  • 做营销的网站推广wordpress后台加载慢
  • 网站做系统叫什么软件吗山东做网站建设公司
  • 本地的赣州网站建设产品设计招聘网站
  • 祝桥建设网站怎样做单页销售网站
  • 二手交易网站开发可参考文献做网站常用的技术有哪些
  • j建设局域网网站四川酒店网站建设
  • 运城做网站费用高吗公司做网站走什么费
  • 建个网站 网页空间多少福建厦门网站建设公司
  • 网站建设百度文库外卖平台app开发多少钱
  • 中国建设银行蚌埠官方网站家乡网页设计模板
  • 寻找企业网站建设安全的集团网站建设
  • 建设一个网站需要哪些硬件设备江西省城乡和住房建设部网站
  • 如何招网站开发人员wordpress wp_tag_cloud
  • 如何做房地产微信推送网站广告网站建设质量保证
  • 承德网站建设规划app开发公司大概多少钱
  • 不同类型网站栏目设置区别西部数码网站管理助手 ftp密码