How to Obtain the System Family?

How to Obtain the System Family?

Anonymous
Not applicable
5,247 Views
3 Replies
Message 1 of 4

How to Obtain the System Family?

Anonymous
Not applicable

Hi everyone, I want to retrieve the Family of the System Elements (such as for example the "Basic Wall" for a wall), but not only the family name. I want at less the ID of this family. It is posible?

 

I know that from Symbols families is posible to obtain it. but i think a Wall doesn't have a FamilySymbol.

0 Likes
Accepted solutions (1)
5,248 Views
3 Replies
Replies (3)
Message 2 of 4

Mustafa.Salaheldin
Collaborator
Collaborator

Here you are, and please don't forget to mark this reply as an answer if it satisfies your needs

#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.Exceptions;
using Autodesk.Revit.Utility;

using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;

#endregion

namespace RevitAddinCS2
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class ExtCmd : IExternalCommand
{
#region Cached Variables

private static ExternalCommandData _cachedCmdData;

public static UIApplication CachedUiApp
{
get
{
return _cachedCmdData.Application;
}
}

public static RvtApplication CachedApp
{
get
{
return CachedUiApp.Application;
}
}

public static RvtDocument CachedDoc
{
get
{
return CachedUiApp.ActiveUIDocument.Document;
}
}

#endregion

#region IExternalCommand Members

public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet)
{
_cachedCmdData = cmdData;

try
{
FilteredElementCollector collector = new FilteredElementCollector(CachedDoc);
collector.OfClass(typeof(ElementType));

StringBuilder sb = new StringBuilder();
List<ElementType> ets = collector.Cast<ElementType>().Where(e => e as FamilySymbol == null).OrderBy(f => f.Name).ToList();
foreach (ElementType item in ets)
{
sb.AppendLine(string.Format("Family Name: {0}, Id: {1}",item.Name,item.Id));

}

TaskDialog.Show("Revit",sb.ToString());

return Result.Succeeded;
}
catch (Exception ex)
{
msg = ex.ToString();
return Result.Failed;
}
}

#endregion

}
}

¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 3 of 4

Anonymous
Not applicable

Dear Mustafa.Salaheldin,

 

thanks for your answer but:

 

By this way I obtain the Type of the element, but i continue without obtain the Family, only can obtain the family Name (in your code: item.FamilyName). For example for the ElementType Generic - 8", i want the wall Family to which it belongs.

 

Actually, only can obtain the Name of this family. It is possible to obtain the Family object or, at least, the Id of it?

 

Thanks

0 Likes
Message 4 of 4

Revitalizer
Advisor
Advisor
Accepted solution

Hi,

 

Walls are not Family based, thus no Family to get.

They reference a WallType, that is the equivalent to a FamilySymbol.

 

If there is a project Family, an in-place Family of category "Walls", this is a special kind of "Wall" since it is a FamilyInstance without a WallType assigned, but with FamilySymbol and Family.

 

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine