69 lines
2.4 KiB
C#
69 lines
2.4 KiB
C#
|
|
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编码";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|