Thursday, 26 March 2009

Parameters in nested families

I was asked if I knew how to access parameters in a nested family using the API, and was sent some sample files. It turned out be more of a Revit user issue than a programmer issue, IMO.

I had to edit the nested family, open up the 'Family Category and Parameters' dialog, and check 'Shared' in the 'Family Parameters' window:



Then I had to reload it into the host family, and reload the host family into my project.

Then using this code, the parameters could be accessed:

Public Shared Function ExtractAll()

Dim elementIterator As Autodesk.Revit.ElementIterator
elementIterator = revitApp.ActiveDocument.Elements


Try

While (elementIterator.MoveNext())
Dim currentElm As Autodesk.Revit.Element
currentElm = elementIterator.Current


WriteOutput("Id = " & currentElm.Id.Value)
WriteOutput("Name = " & currentElm.Name)
WriteOutput("Type = " & elementIterator.Current.GetType.Name)


'go get the parameters
ParameterCheckerNew(currentElm)


End While



Return True

Catch ex As Exception
Debug.Print(Err.Description)
Return False
End Try


End Function


Public Shared Function ParameterCheckerNew(ByVal elem As Autodesk.Revit.Element)
Dim params As ParameterSetIterator = elem.Parameters.GetEnumerator

While params.MoveNext
Dim currentParam As Parameter
currentParam = params.Current
WriteOutput(currentParam.Definition.Name)

Select Case currentParam.StorageType

Case StorageType.Double
WriteOutput(currentParam.AsDouble.ToString)

Case StorageType.Integer
WriteOutput(currentParam.AsInteger.ToString)

Case StorageType.String
WriteOutput(currentParam.AsString)

Case StorageType.ElementId
WriteOutput(currentParam.AsElementId.Value.ToString)

Case StorageType.None
' nothing
Case Else
' nothing
End Select

WriteOutput(currentParam.AsValueString)
End While

End Function




Note above I'm simply looping through every element in the file. This is lazy coding, and you could create any kind of filter you want here to see only the elements you need.

Interestingly I couldn't seem to access it using a selection iterator, as only the host family is recognised as selected, not the nested family within. There's probably a way of drilling down into a selected family and seeing what's nested in it, but I'll take a look at that some other time.

2 comments:

  1. Ed,

    In 2009, if the element in your project was a family, you could access the "Components" or "Others" properties to get the list of elements that are nested inside the family.

    In 2010, you do the equivalent of "Edit Family" and get a new Revit document that you can extract all the elements out of.

    -Matt

    ReplyDelete
  2. Hey Matt,

    I don't entirely understand. Could you please explain how to access this list of nested families in Revit 2009? Is it possible to extract it?

    Greetings,
    Nicholas

    ReplyDelete

Comments are moderated, so you'll have to wait a little bit before they appear!