/// <summary> /// Create a Floor Plan view by Level and View Family Type. /// </summary> /// <param name="level">Level to associate the Plan to.</param> /// <param name="viewFamilyType">View Family Type object.</param> /// <returns name="floorPlan">Floor Plan.</returns> public static Element ByLevelAndType(Level level, [DefaultArgument("Selection.Select.GetNull()")] Element viewFamilyType) { if (level == null || !(level.InternalElement is Autodesk.Revit.DB.Level lvl)) { throw new ArgumentException(nameof(level)); } var doc = DocumentManager.Instance.CurrentDBDocument; Autodesk.Revit.DB.ViewFamilyType vft; if (viewFamilyType == null) { vft = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.ViewFamilyType)) .Cast <Autodesk.Revit.DB.ViewFamilyType>() .FirstOrDefault(x => x.ViewFamily == Autodesk.Revit.DB.ViewFamily.CeilingPlan); } else { vft = viewFamilyType.InternalElement as Autodesk.Revit.DB.ViewFamilyType; } if (vft?.ViewFamily != Autodesk.Revit.DB.ViewFamily.CeilingPlan) { throw new ArgumentException(nameof(viewFamilyType)); } var plan = new CeilingPlanViews(lvl, vft); return(plan.InternalViewPlan.ToDSType(true)); }
private void InitView3D(string name) { var doc = DocumentManager.Instance.CurrentDBDocument; var oldView = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.View3D>(doc); if (oldView != null) { InternalSetView3D(oldView); InternalSetName(name); return; } TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var vft = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.ViewFamilyType)) .Cast <Autodesk.Revit.DB.ViewFamilyType>() .FirstOrDefault(x => x.ViewFamily == Autodesk.Revit.DB.ViewFamily.ThreeDimensional); var view = Autodesk.Revit.DB.View3D.CreateIsometric(doc, vft?.Id); view.Name = name; InternalSetView3D(view); InternalSetName(name); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
public void CreateSharedParameter_ValidArgs() { // shared parameter file workaround string tempfile = System.IO.Path.GetTempFileName().Replace(".tmp", ".txt"); System.IO.Stream stream = System.IO.File.OpenWrite(tempfile); stream.WriteByte(new Byte()); stream.Close(); DocumentManager.Instance.CurrentDBDocument.Application.SharedParametersFilename = tempfile; var def = DocumentManager.Instance.CurrentDBDocument.Application.OpenSharedParameterFile(); var groups = def.Groups; groups.Create("MyGroup"); List <Category> categories = new List <Category>() { Category.ByName("Walls") }; Parameter.CreateSharedParameter("MySharedParameter", "MySharedGroup", Autodesk.Revit.DB.ParameterType.Text.ToString(), Autodesk.Revit.DB.BuiltInParameterGroup.PG_DATA.ToString(), true, categories); var fec = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument).OfClass(typeof(Autodesk.Revit.DB.Wall)); var wall = fec.FirstElement(); Assert.IsNotNull(wall.LookupParameter("MySharedParameter")); }
/// <summary> /// Obtain a Family from the current document given it's name /// </summary> /// <param name="name">The name of the family in the current document</param> /// <returns></returns> public static Family ByName(string name) { if (name == null) { throw new ArgumentNullException(); } TransactionManager.Instance.EnsureInTransaction(Document); // look up the loaded family var fec = new Autodesk.Revit.DB.FilteredElementCollector(Document); fec.OfClass(typeof(Autodesk.Revit.DB.Family)); // obtain the family type with the provided name var families = fec.Cast <Autodesk.Revit.DB.Family>(); var family = families.FirstOrDefault(x => x.Name == name); if (family == null) { throw new Exception(Properties.Resources.FamilySymbolNotFound1); } TransactionManager.Instance.TransactionTaskDone(); return(new Family(family)); }
internal static IEnumerable <Autodesk.Revit.DB.Level> GetAllLevels() { var collector = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument); collector.OfClass(typeof(Autodesk.Revit.DB.Level)); return(collector.ToElements().Cast <Autodesk.Revit.DB.Level>()); }
/// <summary> /// Returns Views that View Filter is applied to. /// </summary> /// <param name="viewFilter">View Filter Element.</param> /// <returns name="view">Views.</returns> /// <search>view, filter, owner</search> public static List <Element> OwnerViews(Element viewFilter) { var doc = DocumentManager.Instance.CurrentDBDocument; var vf = viewFilter.InternalElement as Autodesk.Revit.DB.ParameterFilterElement; var allViews = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.View)) .Cast <Autodesk.Revit.DB.View>() // exclude view templates and views that filters cannot be applied to .Where(x => x.AreGraphicsOverridesAllowed()) .ToList(); var matches = new List <Element>(); foreach (var v in allViews) { var filters = v.GetFilters(); if (filters.Count != 0) { foreach (var id in filters) { var f = doc.GetElement(id) as Autodesk.Revit.DB.ParameterFilterElement; if (vf != null && (f != null && f.Name == vf.Name)) { matches.Add(v.ToDSType(true)); } } } } return(matches); }
/// <summary> /// /// </summary> /// <param name="room"></param> /// <param name="viewFamilyType"></param> /// <returns></returns> public static FloorPlanView ByRoom(Room room, [DefaultArgument("Selection.Select.GetNull()")] Element viewFamilyType) { if (room == null) { throw new ArgumentException(nameof(room)); } var doc = DocumentManager.Instance.CurrentDBDocument; Autodesk.Revit.DB.ViewFamilyType vft; if (viewFamilyType == null) { vft = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.ViewFamilyType)) .Cast <Autodesk.Revit.DB.ViewFamilyType>() .FirstOrDefault(x => x.ViewFamily == Autodesk.Revit.DB.ViewFamily.FloorPlan); } else { vft = viewFamilyType.InternalElement as Autodesk.Revit.DB.ViewFamilyType; } if (!(room.InternalElement is Autodesk.Revit.DB.Architecture.Room rm)) { throw new ArgumentException(nameof(room)); } var plan = new FloorPlanViews(rm.Level, vft); return((FloorPlanView)plan.InternalViewPlan.ToDSType(true)); }
protected static IList <Autodesk.Revit.DB.ReferencePoint> GetAllReferencePoints() { var fec = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentUIDocument.Document); fec.OfClass(typeof(Autodesk.Revit.DB.ReferencePoint)); return(fec.ToElements().Cast <Autodesk.Revit.DB.ReferencePoint>().ToList()); }
public static bool IsOnSheet(View view) { var doc = DocumentManager.Instance.CurrentDBDocument; var v = (Autodesk.Revit.DB.View)view.InternalElement; switch (v.ViewType) { case Autodesk.Revit.DB.ViewType.Undefined: case Autodesk.Revit.DB.ViewType.ProjectBrowser: case Autodesk.Revit.DB.ViewType.SystemBrowser: case Autodesk.Revit.DB.ViewType.Internal: case Autodesk.Revit.DB.ViewType.DrawingSheet: return(false); case Autodesk.Revit.DB.ViewType.FloorPlan: case Autodesk.Revit.DB.ViewType.EngineeringPlan: case Autodesk.Revit.DB.ViewType.AreaPlan: case Autodesk.Revit.DB.ViewType.CeilingPlan: case Autodesk.Revit.DB.ViewType.Elevation: case Autodesk.Revit.DB.ViewType.Section: case Autodesk.Revit.DB.ViewType.Detail: case Autodesk.Revit.DB.ViewType.ThreeD: case Autodesk.Revit.DB.ViewType.DraftingView: case Autodesk.Revit.DB.ViewType.Legend: case Autodesk.Revit.DB.ViewType.Report: case Autodesk.Revit.DB.ViewType.CostReport: case Autodesk.Revit.DB.ViewType.LoadsReport: case Autodesk.Revit.DB.ViewType.PresureLossReport: case Autodesk.Revit.DB.ViewType.Walkthrough: case Autodesk.Revit.DB.ViewType.Rendering: var sheet = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.ViewSheet)) .Cast <Autodesk.Revit.DB.ViewSheet>() .FirstOrDefault(x => x.GetAllPlacedViews().FirstOrDefault(y => y == v.Id) != null); return(sheet != null); case Autodesk.Revit.DB.ViewType.Schedule: case Autodesk.Revit.DB.ViewType.PanelSchedule: case Autodesk.Revit.DB.ViewType.ColumnSchedule: var schedule = v as Autodesk.Revit.DB.ViewSchedule; if (schedule == null) { throw new ArgumentException("Invalid View"); } var sheetSchedule = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.ScheduleSheetInstance)) .Cast <Autodesk.Revit.DB.ScheduleSheetInstance>() .FirstOrDefault(x => !x.IsTitleblockRevisionSchedule && x.ScheduleId == v.Id); return(sheetSchedule != null); default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Retrieve Level by its name. /// </summary> /// <param name="name">Name of the Level.</param> /// <returns>Level.</returns> public static Level GetLevelByName(string name) { var doc = DocumentManager.Instance.CurrentDBDocument; var lvl = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.Level)) .FirstOrDefault(x => x.Name == name); return(lvl?.ToDSType(true) as Level); }
/// <summary> /// Retrieve a TextNoteType by its name. /// </summary> /// <param name="name">Name of the Text Note Type.</param> /// <returns>Text note type.</returns> public static Element GetTextNoteTypeByName(string name) { var doc = DocumentManager.Instance.CurrentDBDocument; var tnt = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.TextNoteType)) .FirstOrDefault(x => x.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ALL_MODEL_TYPE_NAME)?.AsString() == name); return(tnt?.ToDSType(true)); }
public static List <Element> GetAll() { var doc = DocumentManager.Instance.CurrentDBDocument; var sets = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.ViewSheetSet)) .WhereElementIsNotElementType() .Select(x => x.ToDSType(true)) .ToList(); return(sets); }
public void ByAreaSchemeName_NullArgs() { var areaScheme = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument) .OfCategory(Autodesk.Revit.DB.BuiltInCategory.OST_AreaSchemes) .Select(x => x.ToDSType(true)) .FirstOrDefault(); Assert.IsNotNull(areaScheme); Assert.Throws(typeof(ArgumentNullException), () => ScheduleView.CreateAreaSchedule(null, "AreaSchedule_Test")); Assert.Throws(typeof(ArgumentNullException), () => ScheduleView.CreateAreaSchedule(areaScheme, null)); }
/// <summary> /// Returns all elements at a given workset. /// </summary> /// <param name="workset">Workset that we are filtering for.</param> /// <returns name="Element">Elements that passed the workset filter.</returns> public static IList <Element> ByWorkset(Workset workset) { var doc = DocumentManager.Instance.CurrentDBDocument; var filter = new Autodesk.Revit.DB.ElementWorksetFilter(workset.InternalWorkset.Id, false); var elements = new Autodesk.Revit.DB.FilteredElementCollector(doc) .WherePasses(filter) .ToElements() .Select(x => x.ToDSType(true)) .ToList(); return(elements.Any() ? elements : Enumerable.Empty <Element>().ToList()); }
private bool IsNameFree() { IList <Autodesk.Revit.DB.Element> views = new Autodesk.Revit.DB.FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.View)).ToElements(); foreach (Autodesk.Revit.DB.Element ele in views) { if (ele.Name == string.Format("{0} 1", this.name_val)) { return(false); } } return(true); }
public void GetLegend() { var legend = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument) .OfClass(typeof(Autodesk.Revit.DB.View)) .Cast <Autodesk.Revit.DB.View>() .FirstOrDefault(x => x.ViewType == Autodesk.Revit.DB.ViewType.Legend); Assert.NotNull(legend); var wrappedLegend = legend.ToDSType(true); Assert.AreEqual(wrappedLegend.GetType(), typeof(Revit.Elements.Views.Legend)); }
public void CreateProjectParameter_ValidArgs() { List <Category> categories = new List <Category>() { Category.ByName("Walls") }; Parameter.CreateProjectParameter("MyParameter", "MyGroup", Autodesk.Revit.DB.ParameterType.Text.ToString(), Autodesk.Revit.DB.BuiltInParameterGroup.PG_DATA.ToString(), true, categories); var fec = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument).OfClass(typeof(Autodesk.Revit.DB.Wall)); var wall = fec.FirstElement(); Assert.IsNotNull(wall.LookupParameter("MyParameter")); }
public void SetParameterValue_ValidArgs() { var fec = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument).OfClass(typeof(Autodesk.Revit.DB.Wall)); var wall = fec.FirstElement(); var parameter = wall.LookupParameter("Comments"); Assert.IsNotNull(parameter); Parameter DSParam = new Parameter(parameter); Parameter.SetValue(DSParam, "Hello World"); Assert.AreEqual(DSParam.Value, "Hello World"); }
public void ClearAllScheduleFilters_ValidArgs() { var rView = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument) .OfClass(typeof(Autodesk.Revit.DB.ViewSchedule)) .Cast <Autodesk.Revit.DB.ViewSchedule>() .FirstOrDefault(x => x.Name == "Wall Schedule"); var view = ScheduleView.FromExisting(rView, true); Assert.NotNull(view); // remove all schedule filters view.ClearAllFilters(); Assert.AreEqual(view.ScheduleFilters.Count, 0); }
public void ByCurves_ValidArgs() { Autodesk.Revit.DB.FilteredElementCollector collector = new Autodesk.Revit.DB.FilteredElementCollector(Revit.Application.Document.Current.InternalDocument).OfClass(typeof(Autodesk.Revit.DB.FilledRegionType)); FilledRegionType type = FilledRegionType.FromExisting((Autodesk.Revit.DB.FilledRegionType)collector.FirstOrDefault(), true); Assert.NotNull(type); Polygon polygon = Polygon.RegularPolygon(Circle.ByCenterPointRadius(Point.ByCoordinates(0, 0, 0), 10), 4); Assert.NotNull(polygon); var reg = FilledRegion.ByCurves(Revit.Application.Document.Current.ActiveView, polygon.Curves().ToList(), type); Assert.NotNull(reg); }
public void ByAreaSchemeName_ValidArgs() { var areaScheme = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument) .OfCategory(Autodesk.Revit.DB.BuiltInCategory.OST_AreaSchemes) .Select(x => x.ToDSType(true)) .FirstOrDefault(); Assert.IsNotNull(areaScheme); var view = ScheduleView.CreateAreaSchedule(areaScheme, "AreaSchedule_Test"); Assert.NotNull(view); Assert.IsTrue(DocumentManager.Instance.ElementExistsInDocument( new ElementUUID(view.InternalElement.UniqueId))); }
public static bool Exists(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } var doc = DocumentManager.Instance.CurrentDBDocument; var fp = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.FillPatternElement)) .WhereElementIsNotElementType() .Where(x => x.Name == name) .ToList(); return(fp.Any()); }
public static List <Element> AllViewsVisibleIn(Element element, string viewType = null) { if (element == null) { throw new ArgumentNullException(nameof(element)); } var doc = DocumentManager.Instance.CurrentDBDocument; List <Autodesk.Revit.DB.View> viewsToCheck; if (string.IsNullOrWhiteSpace(viewType)) { // (Konrad) Get all valid views by Type var filter = new Autodesk.Revit.DB.ElementMulticlassFilter( new List <Type> { typeof(Autodesk.Revit.DB.View3D), typeof(Autodesk.Revit.DB.ViewPlan), typeof(Autodesk.Revit.DB.ViewSection) }); viewsToCheck = new Autodesk.Revit.DB.FilteredElementCollector(doc) .WherePasses(filter) .Cast <Autodesk.Revit.DB.View>() .Where(x => !x.IsTemplate) .ToList(); } else { var vType = (Autodesk.Revit.DB.ViewType)Enum.Parse(typeof(Autodesk.Revit.DB.ViewType), viewType); if (!CheckType(vType)) { throw new ArgumentException($"{vType.ToString()} does not display elements hence is not valid for this use."); } viewsToCheck = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.View)) .Cast <Autodesk.Revit.DB.View>() .Where(x => x.ViewType == vType && !x.IsTemplate) .ToList(); } return(!viewsToCheck.Any() ? new List <Element>() : FindAllViewsWhereElementIsVisible(element, viewsToCheck)); }
public static Element CreateViaDuplicate(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } var doc = DocumentManager.Instance.CurrentDBDocument; var defaultMat = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(Autodesk.Revit.DB.Material)) .Cast <Autodesk.Revit.DB.Material>() .FirstOrDefault(x => x.AppearanceAssetId != Autodesk.Revit.DB.ElementId.InvalidElementId && x.Name.Contains("Default")); if (defaultMat == null) { throw new Exception("Could not find Default Material to duplicate its Asset;"); } var aaeId = defaultMat.AppearanceAssetId; if (!(doc.GetElement(aaeId) is Autodesk.Revit.DB.AppearanceAssetElement aae)) { throw new Exception("Default Material doesn't have Appearance Asset."); } TransactionManager.Instance.EnsureInTransaction(doc); Autodesk.Revit.DB.AppearanceAssetElement newAae; var count = 1; Restart: try { newAae = aae.Duplicate($"{name}_{count}"); } catch (Exception) { count++; goto Restart; } TransactionManager.Instance.TransactionTaskDone(); return(newAae.ToDSType(true)); }
public void ByLevelAndAreaScheme_BadArgs() { const int elevation = 100; var level = Level.ByElevation(elevation); Assert.NotNull(level); var areaScheme = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument) .OfClass(typeof(Autodesk.Revit.DB.AreaScheme)) .Select(x => x.ToDSType(true)) .FirstOrDefault(); Assert.NotNull(areaScheme); Assert.Throws(typeof(ArgumentNullException), () => AreaPlanView.ByLevelAndAreaScheme(level, null)); Assert.Throws(typeof(ArgumentNullException), () => AreaPlanView.ByLevelAndAreaScheme(null, areaScheme)); }
public void ByElement_ValidArgs() { var line = Line.ByStartPointEndPoint(Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(1000, 0, 0)); Assert.NotNull(line); Autodesk.Revit.DB.FilteredElementCollector collector = new Autodesk.Revit.DB.FilteredElementCollector(Revit.Application.Document.Current.InternalDocument).OfClass(typeof(Autodesk.Revit.DB.WallType)); Revit.Elements.WallType wt = Revit.Elements.WallType.FromExisting((Autodesk.Revit.DB.WallType)collector.FirstOrDefault(), true); var wall = Wall.ByCurveAndHeight(line, 300, Level.ByElevation(100), wt); Assert.NotNull(wall); var tag = Tag.ByElement(Revit.Application.Document.Current.ActiveView, wall, true, false, "Center", "Middle", Vector.ByCoordinates(0, 0, 0)); Assert.NotNull(tag); }
/// <summary> /// Retrieves Survey Point from the model. /// </summary> /// <returns>Survey Point.</returns> public static Point GetSurveyPoint() { var doc = DocumentManager.Instance.CurrentDBDocument; var pts = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfCategory(Autodesk.Revit.DB.BuiltInCategory.OST_SharedBasePoint) .FirstOrDefault(); if (pts == null) { return(null); } var ew = pts.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.BASEPOINT_EASTWEST_PARAM).AsDouble(); var ns = pts.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM).AsDouble(); var elev = pts.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.BASEPOINT_ELEVATION_PARAM).AsDouble(); return(Point.ByCoordinates(ew, ns, elev)); }
public static IList <Element> AtLevel(Level arg) { if (arg == null) { return(null); } var levFilter = new Autodesk.Revit.DB.ElementLevelFilter(arg.InternalLevel.Id); var fec = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument); var instances = fec.WherePasses(levFilter) .WhereElementIsNotElementType() .ToElementIds() .Select(id => ElementSelector.ByElementId(id.IntegerValue)) .ToList(); return(instances); }
/// <summary> /// Select all elements by design option and category. /// </summary> /// <param name="category">Category to filter for.</param> /// <param name="designOption">Design Option to filter for.</param> /// <returns name="Element">Elements.</returns> public static IList <Element> ByCategoryAndDesignOption(Category category, Element designOption) { var doc = DocumentManager.Instance.CurrentDBDocument; var bic = (Autodesk.Revit.DB.BuiltInCategory)Enum.ToObject(typeof(Autodesk.Revit.DB.BuiltInCategory), category.Id); // create design option filter var filter = new Autodesk.Revit.DB.ElementDesignOptionFilter(new Autodesk.Revit.DB.ElementId(designOption.Id)); // select elements var elements = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfCategory(bic) .WherePasses(filter) .WhereElementIsNotElementType() .ToElements() .Select(x => x.ToDSType(true)) .ToList(); return(elements.Any() ? elements : Enumerable.Empty <Element>().ToList()); }
internal static DataStorage GetDataStorage(Document doc, string name) { DataStorage dataStorage = new Autodesk.Revit.DB.FilteredElementCollector(doc) .OfClass(typeof(DataStorage)) .Where(ds => ds.Name == name) .FirstOrDefault() as DataStorage; if (dataStorage == null) { using (Transaction t = new Transaction(doc, "Create data storag")) { t.Start(); dataStorage = DataStorage.Create(doc); dataStorage.Name = name; t.Commit(); } } return(dataStorage); }
/// <summary> /// Obtain a Family from the current document given it's name /// </summary> /// <param name="name">The name of the family in the current document</param> /// <returns></returns> public static Family ByName(string name) { if (name == null) { throw new ArgumentNullException(); } TransactionManager.Instance.EnsureInTransaction(Document); // look up the loaded family var fec = new Autodesk.Revit.DB.FilteredElementCollector(Document); fec.OfClass(typeof(Autodesk.Revit.DB.Family)); // obtain the family symbol with the provided name var families = fec.Cast<Autodesk.Revit.DB.Family>(); var family = families.FirstOrDefault(x => x.Name == name); if (family == null) { throw new Exception("A FamilySymbol with the specified name does not exist in the document"); } TransactionManager.Instance.TransactionTaskDone(); return new Family(family); }