当前位置: 首页 > 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://www.dtcms.com/wzjs/204952.html

相关文章:

  • 如何让网站速度快东莞seo网络营销
  • 洛可可设计公司估值青岛设计优化公司
  • 湛江app开发公司苏州seo关键词优化外包
  • 学校网站管理系统 php百度网站优化工具
  • 龙岩网站设计理念广州seo顾问seocnm
  • 百度推广开户多少钱一个月seo线上培训多少钱
  • 网站如何做引流今日头条最新
  • 免费的国产cad宁波seo网站
  • 没网站怎么做app5年网站seo优化公司
  • 免费的正能量视频素材网站网络营销的用户创造价值
  • 电子商务网站的建设课件网络广告的特点
  • 什么样的网站适合优化seo网站推广计划
  • 做网站简历怎么写网络营销方式
  • 网站整体规划郑州seo招聘
  • wordpress主机分类信息网站seo优
  • 做编程的 网站有哪些方面一件代发48个货源网站
  • 网页设计制作公司报价浑江区关键词seo排名优化
  • asp网站开发技术网站搜索引擎优化
  • thinkphp 做网站如何接广告的平台
  • 客户在我这做的网站被罚seo效果分析
  • 石家庄哪里能制作网站信息服务平台有哪些
  • 手机网站 分辨率惠州网站关键词排名
  • wordpress网站如何加百度搜索百度人工客服24小时电话
  • 网站开发技术指标是什么百度大数据查询平台
  • 网站建设需要哪些素材克州seo整站排名
  • 松岗专业做网站公司关联词有哪些五年级
  • 网游开发培训中心seo作弊
  • 西安学校网站建设哪家专业网址ip地址查询工具
  • 做弩的网站超级软文
  • 公司介绍ppt模板免费下载seo外链建设的方法有