119 lines
4.8 KiB
C#
119 lines
4.8 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using Autodesk.Revit.DB;
|
|||
|
|
using Autodesk.Revit.UI;
|
|||
|
|
using Sai.RvWrapper.Shared;
|
|||
|
|
|
|||
|
|
namespace SZBIM.StandardTools.ParameterManager
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 项目参数(共享参数),项目信息,仅处理轨交的项目信息参数
|
|||
|
|
/// </summary>
|
|||
|
|
public class AddProjectInfoParamsEventHandler : IExternalEventHandler
|
|||
|
|
{
|
|||
|
|
private string transName;
|
|||
|
|
public bool IsSharedProjectParam { get; set; }
|
|||
|
|
public bool IsSharedFamilyParam { get; set; }
|
|||
|
|
public bool IsFamilyParam { get; set; }
|
|||
|
|
public bool IsOnlyProjectCategory { get; set; }
|
|||
|
|
public List<ParamModel> ParameterList { get; set; }
|
|||
|
|
public List<SharedParamModel> SharedParameters { get; set; }
|
|||
|
|
|
|||
|
|
public void Execute(UIApplication uiapp)
|
|||
|
|
{
|
|||
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|||
|
|
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
|
|||
|
|
Document doc = uidoc.Document;
|
|||
|
|
DefinitionFile tempFile;
|
|||
|
|
StringBuilder sb = new StringBuilder();
|
|||
|
|
if (!doc.IsModified)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (doc.IsReadOnly)
|
|||
|
|
{
|
|||
|
|
TaskDialog.Show("提示", "文档为只读;若正在执行命令,请先退出命令!");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (doc.IsFamilyDocument)
|
|||
|
|
{
|
|||
|
|
TaskDialog.Show("提示", "请在项目文档中使用此命令!");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
transName = "添加项目信息";
|
|||
|
|
SharedParamsUtil util = new SharedParamsUtil();
|
|||
|
|
var originSharedParametersFile = uiapp.Application.SharedParametersFilename.Clone();
|
|||
|
|
tempFile = util.CreateTempSharedParameterFile(app, "TempSharedParameters");
|
|||
|
|
doc.Invoke(ts =>
|
|||
|
|
{
|
|||
|
|
var paramDatas = ParameterList.Where(data => data.IsChecked == true);
|
|||
|
|
var g = tempFile.Groups.Create("tempGroup");
|
|||
|
|
foreach (ParamModel paramData in paramDatas)
|
|||
|
|
{
|
|||
|
|
bool isExist = util.IsExistSharedParam(doc, paramData.FullProperty, out _, out _);
|
|||
|
|
if (!isExist)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
foreach (var sharedParameter in SharedParameters)
|
|||
|
|
{
|
|||
|
|
if (sharedParameter.FullParamName == paramData.FullProperty)
|
|||
|
|
{
|
|||
|
|
var categories = uiapp.Application.Create.NewCategorySet();
|
|||
|
|
categories.Insert(Category.GetCategory(doc,
|
|||
|
|
BuiltInCategory.OST_ProjectInformation));
|
|||
|
|
var newInstanceBinding =
|
|||
|
|
uiapp.Application.Create.NewInstanceBinding(categories);
|
|||
|
|
|
|||
|
|
var options =
|
|||
|
|
new ExternalDefinitionCreationOptions(sharedParameter.FullParamName,
|
|||
|
|
ParameterType.MultilineText)
|
|||
|
|
{
|
|||
|
|
GUID = new Guid(sharedParameter.Guid)
|
|||
|
|
};
|
|||
|
|
var definition = g.Definitions.get_Item(sharedParameter.FullParamName);
|
|||
|
|
if (definition == null)
|
|||
|
|
{
|
|||
|
|
definition = g.Definitions.Create(options);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
doc.ParameterBindings.Insert(definition, newInstanceBinding,
|
|||
|
|
BuiltInParameterGroup.PG_IDENTITY_DATA);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
File.Delete(tempFile.Filename);
|
|||
|
|
uiapp.Application.SharedParametersFilename = originSharedParametersFile.ToString();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}, transName);
|
|||
|
|
File.Delete(tempFile.Filename);
|
|||
|
|
uiapp.Application.SharedParametersFilename = originSharedParametersFile.ToString();
|
|||
|
|
if (string.IsNullOrEmpty(sb.ToString()))
|
|||
|
|
{
|
|||
|
|
TaskDialog.Show("提示", "添加完成!");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
TaskDialog.Show("警告", sb.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetName()
|
|||
|
|
{
|
|||
|
|
return transName;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|