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

定西市建设厅官方网站百度关键词优化平台

定西市建设厅官方网站,百度关键词优化平台,wordpress 卡片插件,dede批量建站配置文件的读取 在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/508012.html

相关文章:

  • 企业网站开发的背景和意义南昌seo数据监控
  • 无锡网站建设和网站建设运营
  • 青岛抖音广告seo官网优化怎么做
  • wordpress 导航站模板下载网站排名优化方法
  • 建网站做站长百度营销推广官网
  • ps做产品的网站草莓永久地域网名入2022
  • 安徽静安集团网站建设国内搜索引擎优化的公司
  • 网站建设与安全管理新媒体运营培训班
  • 重庆专门做网站的公司百度信息流广告代理
  • 郑州app软件定制开发关键词优化排名
  • g4560做网站服务器北京刚刚宣布比疫情更可怕的事情
  • 网站负责人拍照优化网站快速排名软件
  • 东莞专业做外贸网站百度推广广告收费标准
  • h5网站模板开发短视频seo询盘系统
  • wap网站建设方案北京百度seo排名
  • 澳门网站开发郴州网站建设网络推广平台
  • 自己做的网站怎么放到小程序磁力狗在线
  • wordpress全局pjax抖音seo
  • 网站优化seo四个建议网页设计代做
  • 保定网站建设制作开发平台百度手机版
  • 家里笔记本做网站 怎么解析营销策略ppt
  • 网站上文章加入音乐是怎么做的北京做百度推广的公司
  • 网站设计的出路seo顾问阿亮博客
  • 做网站需要什么认证全网投放广告的渠道有哪些
  • 网络推广需要做哪些工作淘宝seo是什么意思
  • 基于php网站建设论文餐饮培训
  • 合肥网站开发建设重庆森林为什么不能看
  • 网站做app开发工具成都关键词优化服务
  • wordpress网站自适应做app软件大概多少钱
  • 网站做产品的审核工作内容计算机培训班