Element.LookupParameter Issue

Element.LookupParameter Issue

Anonymous
Not applicable
3,107 Views
3 Replies
Message 1 of 4

Element.LookupParameter Issue

Anonymous
Not applicable

I am having difficulties getting the Family Element of a FamilyInstance using the "Lookup" method.

 

TRY 1 - The "AsValueString methods returns the Family Name and not the family

 

 

string getFamily(FamilyInstance FI)
{
 return FI.LookupParameter("Family").AsValueString()
}

 

 

 

TRY 2 - The "AsElementId" method of the "Family" Parameter returns the FamilySymbol Id and not the Family Id

 

 

string getFamily(FamilyInstance FI)
{
  ElementId EI = FI.LookupParameter("Family").AsElementId()
  return FI.Document.GetElement(EI).Name
}

 

 

 

TRY 3 - The "AsElementId" method of the "Family and Type" Parameter returns again the FamilySymbol Id and not the Family Id

 

 

string getFamily(FamilyInstance FI)
{
  ElementId EI = FI.LookupParameter("Family and Type").AsElementId()
  return FI.Document.GetElement(EI).Name
}

 

 

 

TRY 4 - The "AsValueString" method of the "Family Name" Parameter returns null. That is very confusing.

 

 

string getFamily(FamilyInstance FI)
{
  ElementId EI = FI.LookupParameter("Family Name").AsElementId()
  return FI.Document.GetElement(EI).Name
}

 

 

Does the above mean that parameters may store string but not elements correctly?

0 Likes
3,108 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

FamilyInstance Lookup method is not reliable.

 

I checked the statement below. This unfortunately results true!!

 

bool CompareFamilyVsTypeIdUsingLookupParameter(FamilyInstance FI)
{
  return FI.LookupParameter("Type").AsElementId() == FI.LookupParameter("Family").AsElementId()
}

 

 

0 Likes
Message 3 of 4

RPTHOMAS108
Mentor
Mentor

If those are built in Parameters (which they seem to be) then you should be getting the parameter by no other way than with it's built in parameter enum value. With LookupParameter you get the first match with a given name.

 

AsValueString is a convenience method you should avoid using this and instead review the storage type of the parameter and use the specific Parmeter.As... method; i.e. .AsString not .AsValueString should be used when the storage type is string.

 

AsValueString is most useful when the value is of storage type double and has Units since it converts from internal units and adds the unit symbol according to UI units set. However you can use the unit conversion utilities for that.

 

'Family Name', 'FamilySymbol', 'Family' are all things you can get from the methods within the various API class objects. You should not need to go anywhere near parameters for these items. 

 

Element.GetTypeID -> ElmentID (ID of ElementType such as FamilySymbol)

Name is overridden as writeonly at ElementType therefore don't cast an Element (which is an ElementType) to ElementType to get Name. Leave as Element and get from Element.Name.

FamilySymbol.Name  use FamilySymbol -> Element.Name

FamilySymbol.Family.Name

 

 

 

 

 

 

0 Likes
Message 4 of 4

jeremytammik
Autodesk
Autodesk

The Building Coder has discussed all the questions you raise many times over, including many other aspects of reading parameters as well.

 

Richard mentions a few important points; thank you very much for that, Richard!

 

Here are some hints that come to mind:

 

 

The results that you list above all make perfect sense.

 

They can be easily explained like this:

 

  • A family instance always refers to its family symbol; to do so, it uses an element id.
  • The family symbol always refers to its parent family; to do so, it again uses an element id.

 

Therefore, you can easily retrieve the element id of a family from an instance like this:

 

BuiltInParameter bip_of_symbol = ???
BuiltInParameter bip_of_family = ???

ElementId id_symbol = instance.Get( bip_of_symbol )
Element symbol = doc.GetElement( id_symbol )
ElementId id_family = symbol.Get( bip_of_family )
Element family = doc.GetElement( id_family )

  

To determine the suitable built-in parameter enumeration values to use, please explore your family instance using RevitLookup.

  

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes