qin
2024-08-27 8d6cdf37178ba699f04d61dbaee89f81ff83c488
HStation.RevitDev/RevitDataExport/Forms/Form_FamilyManager.cs
@@ -1,6 +1,9 @@
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using DevExpress.Utils.Extensions;
using HStation.RevitDev.Model.ModelEnum;
using HStation.RevitDev.RevitDataExport.Common;
using HStation.RevitDev.RevitDataExport.Entity;
using HStation.RevitDev.RevitDataExport.Utility;
using System;
using System.Drawing;
@@ -13,12 +16,16 @@
    public partial class Form_FamilyManager : System.Windows.Forms.Form
    {
        ExternalCommandData _data;
        private ExternalEvent_Execute externalEvent_Execute;
        private ExternalEvent externalEvent;
        public Form_FamilyManager(ExternalCommandData data)
        {
            _data = data;
            InitializeComponent();
            InitializeControls();
            externalEvent_Execute = new ExternalEvent_Execute("Ex");
            externalEvent = ExternalEvent.Create(externalEvent_Execute);
        }
        private void InitializeControls()
@@ -29,7 +36,7 @@
        private void InitFamilyPanel()
        {
        }
        private void InitTreeView()
@@ -57,7 +64,7 @@
            if (!revitType.IsRequired()) { return; }
            var dscribe = revitType.GetDescription();
            var dir = Path.Combine(GlobalResource.FamilysDirectory, dscribe);
            if (!Directory.Exists(dir))
            if (!Directory.Exists(dir))
            {
                TaskDialog.Show("错误", $"未找到{dscribe}目录");
                return;
@@ -121,6 +128,7 @@
                    CopyToImageDirectory(ref path, revitType);
                    Bitmap bitmap = GetRfaThumbnail(dir, path);
                    Button btn = CreateButton(bitmap, path, revitType);
                    CreateParams(path, revitType);
                    flowLayoutPanel_familys.Controls.Add(btn);
                }
            }
@@ -129,6 +137,278 @@
                TaskDialog.Show("错误", $"{ex.Message}");
            }
            TaskDialog.Show("提示", "添加成功!");
        }
        private void CreateParams(string path, RevitType revitType)
        {
            if (File.Exists(path))
            {
                if (externalEvent != null)
                {
                    externalEvent_Execute.ExecuteAction = new Action<UIApplication>((app) =>
                    {
                        var doc = _data.Application.ActiveUIDocument.Document;
                        var fdoc = doc.Application.OpenDocumentFile(path);
                        var fm = fdoc.FamilyManager;
                        var ls = GetParamsList().Where(c => c.FamilyType.Equals(revitType.GetDescriptioin()));
                        if (ls != null && ls.Any())
                        {
                            using (var trans = new Transaction(fdoc, "addParameters"))
                            {
                                trans.Start();
                                ls.ForEach(c =>
                                {
                                    var ps = fm.get_Parameter(c.ParamsName);
                                    if (ps == null)
                                    {
                                        fm.AddParameter(c.ParamsName, Autodesk.Revit.DB.BuiltInParameterGroup.PG_GENERAL, Autodesk.Revit.DB.ParameterType.Text, true);
                                    }
                                    if (!string.IsNullOrEmpty(c.DefaultValue))
                                    {
                                        var sp = fm.get_Parameter(c.ParamsName);
                                        if (sp != null)
                                        {
                                            fm.Set(sp, c.DefaultValue);
                                        }
                                    }
                                });
                                trans.Commit();
                            }
                        }
                        fdoc.Close();
                    });
                    externalEvent.Raise();
                }
            }
        }
        private System.Collections.Generic.List<FamilyParamsModel> GetParamsList()
        {
            var ls = new System.Collections.Generic.List<FamilyParamsModel>() {
            #region 水泵
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="水泵状态",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="上游标高",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="下游标高",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="上游初始水质",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="下游初始水质",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="额定功率",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="流量扬程曲线",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="转速比",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="转速比模式",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="能耗价格",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="价格模式",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="流量效率曲线",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水泵", ParamsName="是否自定义",DefaultValue="是"},
                #endregion
             #region 管道
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="管道状态",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="上游标高",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="下游标高",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="上游初始水质",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="下游初始水质",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="直径",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="长度",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="粗糙系数",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="局部阻力系数",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="管道", ParamsName="是否自定义",DefaultValue="是"},
                #endregion
             #region 换热器
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="管道状态",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="上游标高",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="下游标高",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="上游初始水质",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="下游初始水质",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="直径",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="长度",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="粗糙系数",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="局部阻力系数",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="换热器", ParamsName="是否自定义",DefaultValue="是"},
            #endregion
             #region 阀门
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="阀门状态",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="上游标高",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="下游标高",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="上游初始水质",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="下游初始水质",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="直径",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="阀门类型",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="阀门设置",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="局部阻力系数",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="阀门", ParamsName="是否自定义",DefaultValue="是"},
            #endregion
             #region 喷淋头
             new FamilyParamsModel(){ FamilyType="喷淋头", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="喷淋头", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="喷淋头", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="喷淋头", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="喷淋头", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="喷淋头", ParamsName="初始水质",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="喷淋头", ParamsName="喷射系数",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="喷淋头", ParamsName="标高信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="喷淋头", ParamsName="需水量",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="喷淋头", ParamsName="需水模式",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="喷淋头", ParamsName="是否自定义",DefaultValue="是"},
            #endregion
             #region 闷头
             new FamilyParamsModel(){ FamilyType="闷头", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="闷头", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="闷头", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="闷头", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="闷头", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="闷头", ParamsName="初始水质",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="闷头", ParamsName="标高信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="闷头", ParamsName="需水量",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="闷头", ParamsName="需水模式",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="闷头", ParamsName="是否自定义",DefaultValue="是"},
            #endregion
             #region 三通
             new FamilyParamsModel(){ FamilyType="三通", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="三通", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="三通", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="三通", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="三通", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="三通", ParamsName="初始水质",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="三通", ParamsName="标高信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="三通", ParamsName="需水量",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="三通", ParamsName="需水模式",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="三通", ParamsName="是否自定义",DefaultValue="是"},
            #endregion
             #region 四通
             new FamilyParamsModel(){ FamilyType="四通", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="四通", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="四通", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="四通", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="四通", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="四通", ParamsName="初始水质",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="四通", ParamsName="标高信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="四通", ParamsName="需水量",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="四通", ParamsName="需水模式",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="四通", ParamsName="是否自定义",DefaultValue="是"},
            #endregion
             #region 水表
             new FamilyParamsModel(){ FamilyType="水表", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水表", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水表", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水表", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水表", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水表", ParamsName="初始水质",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="水表", ParamsName="标高信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水表", ParamsName="需水量",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水表", ParamsName="需水模式",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水表", ParamsName="是否自定义",DefaultValue="是"},
            #endregion
             #region 弯头
             new FamilyParamsModel(){ FamilyType="弯头", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="弯头", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="弯头", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="弯头", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="弯头", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="弯头", ParamsName="初始水质",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="弯头", ParamsName="标高信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="弯头", ParamsName="需水量",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="弯头", ParamsName="需水模式",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="弯头", ParamsName="是否自定义",DefaultValue="是"},
            #endregion
              #region 过渡件
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="管道状态",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="上游标高",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="下游标高",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="上游初始水质",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="下游初始水质",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="直径",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="长度",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="粗糙系数",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="局部阻力系数",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="过渡件", ParamsName="是否自定义",DefaultValue="是"},
            #endregion
             #region 消火栓
             new FamilyParamsModel(){ FamilyType="消火栓", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="消火栓", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="消火栓", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="消火栓", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="消火栓", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="消火栓", ParamsName="初始水质",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="消火栓", ParamsName="流量系数",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="消火栓", ParamsName="标高信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="消火栓", ParamsName="需水量",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="消火栓", ParamsName="需水模式",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="消火栓", ParamsName="是否自定义",DefaultValue="是"},
            #endregion
             #region 水库
             new FamilyParamsModel(){ FamilyType="水库", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水库", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水库", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水库", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水库", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水库", ParamsName="初始水质",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="水库", ParamsName="池底标高",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水库", ParamsName="总水头",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水库", ParamsName="水头模式",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水库", ParamsName="是否自定义",DefaultValue="是"},
            #endregion
             #region 水箱
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="名称",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="编码",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="型号信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="标签",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="说明信息",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="初始水质",DefaultValue="Open"},
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="池底标高",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="初始水位",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="最低水位",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="最高水位",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="直径",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="最小容积",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="容积曲线",DefaultValue=""},
             new FamilyParamsModel(){ FamilyType="水箱", ParamsName="是否自定义",DefaultValue="是"},
                #endregion
             #region 其他
             #endregion
            };
            //File.WriteAllText(GlobalResource.ParamsFilePath, JsonHelper.ToJson(ls));
            return ls;
        }
        private void CopyToImageDirectory(ref string path, RevitType revitType)
@@ -154,7 +434,7 @@
        {
            string fileName = Path.GetFileName(rfaPath);
            ContextMenu menu = CreateContextMenu();
            Button btn = new Button();
            btn.ContextMenu = menu;
            btn.Tag = revitType;