qin
2024-09-28 e358beb08f5be49703009b64f058ecfbcfeefbd9
HStation.RevitDev/RevitDataExport/Utility/CacheUtil.cs
@@ -8,6 +8,7 @@
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Autodesk.Revit.UI;
namespace HStation.RevitDev.RevitDataExport.Utility
{
@@ -84,17 +85,17 @@
            err = "";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                var tempDir = Path.Combine(Path.GetDirectoryName(GlobalResource.BinDirectory), "temp"); //"d:\\temp";
                if (!Directory.Exists(tempDir))
                    Directory.CreateDirectory(tempDir);
                var structFile = tempDir + "\\struct.json";
                var modelFile = tempDir + "\\model.rvt";
                var settingFile = tempDir + "\\setting.json";
                var otherFile = tempDir + "\\struct_others.json";
                try
                {
                    var zipFilePath = dialog.SelectedPath + "\\model.ywrvt";
                    var tempDir = "d:\\temp";
                    if (!Directory.Exists(tempDir))
                        Directory.CreateDirectory(tempDir);
                    var structFile = tempDir + "\\struct.json";
                    var modelFile = tempDir + "\\model.rvt";
                    var settingFile = tempDir + "\\setting.json";
                    var otherFile = tempDir + "\\struct_others.json";
                    if (File.Exists(structFile)) File.Delete(structFile);
                    if (File.Exists(modelFile)) File.Delete(modelFile);
@@ -122,10 +123,16 @@
                    File.Delete(otherFile);
                    File.Delete(modelFile);
                    File.Delete(settingFile);
                    File.Delete(otherFile);
                    return true;
                }
                catch (Exception ex)
                {
                    File.Delete(structFile);
                    File.Delete(otherFile);
                    File.Delete(modelFile);
                    File.Delete(settingFile);
                    File.Delete(otherFile);
                    err = JsonHelper.ToJson(ex);
                    return false;
                }
@@ -176,19 +183,58 @@
            {
                return;
            }
            GlobalResource.HideMode = !GlobalResource.HideMode;
            using (Transaction trans = new Transaction(document, "hide elements"))
            try
            {
                trans.Start();
                if (GlobalResource.HideMode)
                GlobalResource.HideMode = !GlobalResource.HideMode;
                using (Transaction trans = new Transaction(document, "hide elements"))
                {
                    document.ActiveView.HideElements(ids);
                    trans.Start();
                    if (GlobalResource.HideMode)
                    {
                        document.ActiveView.HideElements(ids);
                    }
                    else
                    {
                        document.ActiveView.UnhideElements(ids);
                    }
                    trans.Commit();
                }
                else
            }
            catch (Exception ex)
            {
                TaskDialog.Show("错误", "显隐失败,可能存在不能设置隐藏的构件!");
            }
        }
        public static void HideOrShowOtherModels(Document document)
        {
            if (document == null) { return; }
            var ids = GlobalResource.RevitModels.GetOtherIds()?.Select(x => new ElementId(int.Parse(x))).ToList();
            if (ids.Count == 0)
            {
                return;
            }
            try
            {
                GlobalResource.IsOtherHidden = !GlobalResource.IsOtherHidden;
                using (Transaction trans = new Transaction(document, "hide other elements"))
                {
                    document.ActiveView.UnhideElements(ids);
                    trans.Start();
                    if (GlobalResource.IsOtherHidden)
                    {
                        document.ActiveView.HideElements(ids);
                    }
                    else
                    {
                        document.ActiveView.UnhideElements(ids);
                    }
                    trans.Commit();
                }
                trans.Commit();
            }
            catch (Exception ex)
            {
                TaskDialog.Show("错误", "显隐失败,可能存在不能设置隐藏的构件!");
            }
        }
    }