| | |
| | | using Autodesk.Revit.DB; |
| | | using HStation.RevitDev.RevitDataExport.Entity; |
| | | using System; |
| | | using System.IO; |
| | | using System.Linq; |
| | | |
| | |
| | | { |
| | | public class CacheUtil |
| | | { |
| | | public static void ReadCache(Document doc) |
| | | public static void InitCache(Document doc) |
| | | { |
| | | var filePath = doc.PathName; |
| | | var cache = File.ReadAllText(Common.GlobalResource.ConfigFilePath); |
| | |
| | | if (record != null) |
| | | { |
| | | Common.GlobalResource.RevitModels = record.Record; |
| | | foreach (var pair in record.Record)
|
| | | {
|
| | | Common.GlobalResource.ElementIds.AddRange(pair.Value);
|
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | records = Newtonsoft.Json.JsonConvert.DeserializeObject<Records>(cache); |
| | | } |
| | | var configRecord = records.ConfigRecords.Where(x => x.FilePath == doc.PathName)?.FirstOrDefault(); |
| | | var configRecord = records.ConfigRecords?.Where(x => x.FilePath == doc.PathName)?.FirstOrDefault(); |
| | | if (configRecord == null) |
| | | { |
| | | records.ConfigRecords.Add(record); |
| | |
| | | |
| | | var config = Newtonsoft.Json.JsonConvert.SerializeObject(records); |
| | | File.WriteAllText(Common.GlobalResource.ConfigFilePath, config); |
| | | } |
| | | }
|
| | |
|
| | | public static void HideOrShowModels(Document document)
|
| | | {
|
| | | if (document == null) { return; }
|
| | | var ids = Common.GlobalResource.ElementIds.Select(x => new ElementId(int.Parse(x))).ToList();
|
| | | if (ids.Count == 0)
|
| | | {
|
| | | return;
|
| | | }
|
| | | Common.GlobalResource.HideMode = !Common.GlobalResource.HideMode;
|
| | | using (Transaction trans = new Transaction(document, "hide elements"))
|
| | | {
|
| | | trans.Start();
|
| | | if (Common.GlobalResource.HideMode)
|
| | | {
|
| | | document.ActiveView.HideElements(ids);
|
| | | }
|
| | | else
|
| | | {
|
| | | document.ActiveView.UnhideElements(ids);
|
| | | }
|
| | | trans.Commit();
|
| | | }
|
| | | }
|
| | | } |
| | | } |