We have talked about implementing a sample IFamilyLoadOptions interface previously. In this post, let’s see how Family Optional Loader of RevitAddinWizard can assist us to do the same work.
Family Optional Loader can be found from the Revit Addin category of the Project Items window:
Its welcome page looks like:
Input options for the FamilyFound case:
Input options for the SharedFamilyFound case:
In the summary page, we can review whether all settings are as expected. If not we still have a chance to go back to previous pages and change them.
After the Finish button is pressed, a Family Optional Loader will be created as follows:
#region Namespaces
using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;
using Autodesk.Revit.Collections;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.Utility;
using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;
#endregion
namespace RevitAddinCS4
{
public class FamilyOptionalLoader1 : IFamilyLoadOptions
{
#region IFamilyLoadOptions Members
public bool OnFamilyFound(bool familyInUse, ref bool overwriteParameterValues)
{
if( !familyInUse )
{
overwriteParameterValues = true;
return true;
}
else
{
overwriteParameterValues = true;
return true;
}
}
public bool OnSharedFamilyFound(Family sharedFamily, bool familyInUse, ref FamilySource source, ref bool overwriteParameterValues)
{
if (!familyInUse)
{
source = FamilySource.Project;
overwriteParameterValues = true;
return true;
}
else
{
source = FamilySource.Project;
overwriteParameterValues = true;
return true;
}
}
#endregion
}
}
In addition, a help method will also be added to the chosen external command class:
public static ElementId OptionalLoadFamily(RvtDocument doc, string filename)
{
Transaction trans = new Transaction(doc, "OptionalLoadFamily");
trans.Start();
ElementId id;
try
{
Family family;
doc.LoadFamily(filename, new FamilyOptionalLoader1(), out family);
trans.Commit();
id = family.Id;
}
catch
{
trans.RollBack();
id = ElementId.InvalidElementId;
}
return id;
}
Give Family Optional Loader of RevitAddinWizard a try and you will get all these in no time.
Recent Comments