初めての Revit プラグインを作成しようとしています。
Revit 2014 を使用していますが、ファイルからロードしたファミリの単一のインスタンスを配置したいと考えています。私は実際にこのコードを使用しています:
[TransactionAttribute(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
public class InsertFamily : IExternalCommand
{
readonly List<ElementId> _addedElementIds = new List<ElementId>();
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Document document = uiApp.ActiveUIDocument.Document;
FamilySymbol family = null;
bool good = false;
using (var trans = new Transaction(document, "inserting family"))
{
trans.Start();
good = document.LoadFamilySymbol(@"my file path.rfa", "my type", new FamilyLoadingOverwriteOption(), out family);
trans.Commit();
}
if (good && family != null)
{
_addedElementIds.Clear();
uiApp.Application.DocumentChanged += applicationOnDocumentChanged;
uiApp.ActiveUIDocument.PromptForFamilyInstancePlacement(family);
uiApp.Application.DocumentChanged -= applicationOnDocumentChanged;
}
return Result.Succeeded;
}
private void applicationOnDocumentChanged(object sender, DocumentChangedEventArgs documentChangedEventArgs)
{
_addedElementIds.AddRange(documentChangedEventArgs.GetAddedElementIds());
}
}
class FamilyLoadingOverwriteOption : IFamilyLoadOptions
{
public bool OnFamilyFound(bool familyInUse, out bool overwriteParameterValues)
{
overwriteParameterValues = true;
return true;
}
public bool OnSharedFamilyFound(Family sharedFamily, bool familyInUse, out FamilySource source, out bool overwriteParameterValues)
{
source = FamilySource.Family;
overwriteParameterValues = true;
return true;
}
}
問題は、この方法PromptForFamilyInstancePlacement
ではユーザーがファミリの複数のインスタンスを挿入できることです。ユーザーがプロジェクトに挿入できるインスタンスは 1 つだけです。挿入されたインスタンスを戻すためのコードも記述します (DocumentChanged
ご覧のとおり、イベントを使用)。