添加项目文件。
This commit is contained in:
69
RevitKits/WBSCoder/CodingEventHandler.cs
Normal file
69
RevitKits/WBSCoder/CodingEventHandler.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
using Sai.RvWrapper.Shared;
|
||||
|
||||
namespace Sai.Common.Shared.WBSCoder
|
||||
{
|
||||
public class CodingEventHandler : IExternalEventHandler
|
||||
{
|
||||
public TaskItem TaskItem { get; set; }
|
||||
|
||||
public void Execute(UIApplication app)
|
||||
{
|
||||
var uidoc = app.ActiveUIDocument;
|
||||
Document doc = uidoc.Document;
|
||||
try
|
||||
{
|
||||
var elemIds = app.ActiveUIDocument.Selection.GetElementIds();
|
||||
if (elemIds.Count > 0)
|
||||
{
|
||||
using (Transaction trans = new Transaction(doc, "添加WBS编码"))
|
||||
{
|
||||
trans.Start();
|
||||
foreach (var id in elemIds)
|
||||
{
|
||||
Element e = uidoc.Document.GetElement(id);
|
||||
var param = e.get_Parameter(BuiltInParameter.ALL_MODEL_MARK);
|
||||
if (param != null)
|
||||
{
|
||||
param.Set(TaskItem.WBSCode);
|
||||
}
|
||||
}
|
||||
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var refers = app.ActiveUIDocument.Selection.PickObjects(ObjectType.Element,
|
||||
new TypesSelectionFilter(typeof(FamilyInstance), typeof(HostObject)), "请选择元素添加WBS编码");
|
||||
using (Transaction trans = new Transaction(doc, "添加WBS编码"))
|
||||
{
|
||||
trans.Start();
|
||||
foreach (var refer in refers)
|
||||
{
|
||||
Element e = uidoc.Document.GetElement(refer);
|
||||
var param = e.get_Parameter(BuiltInParameter.ALL_MODEL_MARK);
|
||||
if (param != null)
|
||||
{
|
||||
param.Set(TaskItem.WBSCode);
|
||||
}
|
||||
}
|
||||
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
||||
{
|
||||
}
|
||||
//app.ActiveUIDocument.SaveAs();
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return "添加WBS编码";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user