57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.UI;
|
|
using RookieStation.CommonTools.Model;
|
|
using RookieStation.Extension;
|
|
using RookieStation.Utils;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace RookieStation.CommonTools.ExtHandler
|
|
{
|
|
internal class LoadFamilyHandler : IExternalEventHandler
|
|
{
|
|
public FamilyInfo FamilyInfo { get; set; }
|
|
|
|
public void Execute(UIApplication app)
|
|
{
|
|
try
|
|
{
|
|
Document doc = app.ActiveUIDocument.Document;
|
|
RsFamilyLoadOption familyLoadOption = new RsFamilyLoadOption();
|
|
Family family = null;
|
|
FamilySymbol fs = null;
|
|
|
|
doc.Invoke(ts =>
|
|
{
|
|
var canloaded = doc.LoadFamily(FamilyInfo.FullFileName, familyLoadOption, out family);
|
|
if (canloaded)
|
|
{
|
|
fs = doc.GetElement(family.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
|
|
if (!fs.IsActive)
|
|
{
|
|
fs.Activate();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TaskDialog.Show("温馨提示", "族已载入或载入失败。");
|
|
}
|
|
}, "载入-" + FamilyInfo.Title);
|
|
if (fs != null)
|
|
{
|
|
app.ActiveUIDocument.PromptForFamilyInstancePlacement(fs);
|
|
//app.ActiveUIDocument.PromptToPlaceElementTypeOnLegendView(fs);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.WriteLog(e.Message);
|
|
}
|
|
}
|
|
|
|
public string GetName()
|
|
{
|
|
return "加载族";
|
|
}
|
|
}
|
|
} |