PDA

View Full Version : Get family Name and type



anthonyf
2008-04-15, 09:16 AM
Hi,

Does anyone have an example, or can someone point me in the right direction?
I'm trying to find a detail components file name, I can get the type but the file name eludes me, my code below

Public Function Execute(ByVal CommandData As ExternalCommandData, ByRef message As String, ByVal elements As Autodesk.Revit.ElementSet) As Autodesk.Revit.IExternalCommand.Result Implements Autodesk.Revit.IExternalCommand.Execute
Try

Dim app As Autodesk.Revit.Application = CommandData.Application
'get the elements selected
' The current selection can be retrieved from the active
' document via the selection object
Dim seletion As SelElementSet = app.ActiveDocument.Selection.Elements

' check that the user has selected some elements
If seletion.Size >= 1 Then

Dim ElementIter As IEnumerator 'iterator for the element set

ElementIter = CommandData.Application.ActiveDocument.Selection.Elements.ForwardIterator

'Loop through the elements
Do While ElementIter.MoveNext
'Get the current element in the iterator
Dim objElement As Autodesk.Revit.Element = ElementIter.Current
'Text is not a Type (symbol), so filter those out
If Not (TypeOf objElement Is Autodesk.Revit.Symbol) Then
'Check the element's category

Dim Category As Autodesk.Revit.Category = objElement.Category
If Not (Category Is Nothing) Then
If Category.Name = "Detail Items" Then
'Display selected item name
MsgBox(objElement.Name)

End If

End If
End If
Loop

End If

Catch ex As Exception
'return a failed result and show the user the error
message = ex.Message
Return IExternalCommand.Result.Failed
End Try

End Function

mmason.65315
2008-04-15, 12:27 PM
You're getting the name of the FamilyInstance element, which by default is the "type" name.

If you want the family name, you'll have to "walk" your way up from instance to familysymbol (type) to the family.

Something like this...


Dim objType As Autodesk.Revit.Symbols.FamilySymbol = objElement.ObjectType
Dim objFamily As Autodesk.Revit.Elements.Family = objType.Family

MsgBox( objFamily.Name )


Good Luck,
Matt

anthonyf
2008-04-15, 07:27 PM
Thanks Matt
I'll give that a go and post my results.

mpruna
2008-04-16, 01:22 PM
my code is in C#, this is how you browse the model for family symbols (app is your revit connection,I assume you already have a variable for that):

Autodesk.Revit.ElementIterator allObjects = app.ActiveDocument.Elements;

while (allObjects.MoveNext())
{
element = allObjects.Current as Autodesk.Revit.Element;
FamilySymbol symbol = element as FamilySymbol;
}

to get type of symbol refer to:
symbol.Category.Name

to get name:
symbol.Name


Hope this helps

anthonyf
2008-04-17, 06:59 AM
Hi Matt
Thanks for your help, your code was spot on.