123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- /*-------------------------------------------------------------------------
- * 功能描述:FileSwitch
- * 作者:xulisong
- * 创建时间: 2019/5/28 10:31:29
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using Autodesk.Revit.DB;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FWindSoft.Revit
- {
- /// <summary>
- /// 文件状态
- /// </summary>
- [Flags]
- public enum DocumentState
- {
- /// <summary>
- /// 不可用
- /// </summary>
- Invalid=0,
- /// <summary>
- /// 操作前,已经打开
- /// </summary>
- Exist=1,
- /// <summary>
- /// 操作时,实时打开
- /// </summary>
- New=2,
- }
- /// <summary>
- /// revit 文件开关
- /// </summary>
- public class RevitFileSwitch
- {
- public RevitFileSwitch(string path)
- {
- Path = path;
- State = DocumentState.Invalid;
- }
- /// <summary>
- /// 文件路径
- /// </summary>
- public string Path { get; private set; }
- /// <summary>
- /// 关联revit文件
- /// </summary>
- public Document Document { get; private set; }
- /// <summary>
- /// 文件状态
- /// </summary>
- public DocumentState State { get; private set; }
- /// <summary>
- /// 打开模型
- /// </summary>
- public void On()
- {
- if (this.Document != null)
- {
- return;
- }
- string path = Path;
- var sets = RevitCore.App.Documents;
- if (Path == null || !File.Exists(path))
- {
- return;
- }
- foreach (Document document in sets)
- {
- if (document.PathName == path)
- {
- Document = document;
- State = DocumentState.Exist;
- break;
- }
- }
- if (Document == null)
- {
- Document = RevitCore.App.OpenDocumentFile(path);
- State = DocumentState.New;
- }
- }
- /// <summary>
- /// 关闭模型
- /// </summary>
- public void Off()
- {
- Document?.Close();
- }
- /// <summary>
- /// 关闭新状态的模型
- /// </summary>
- public void OffNew()
- {
- if (DocumentState.New == State)
- {
- Document?.Close();
- }
- }
- }
- }
|