Id of a nested element in parameter reports different value

Id of a nested element in parameter reports different value

homer_anave
Contributor Contributor
1,076 Views
2 Replies
Message 1 of 3

Id of a nested element in parameter reports different value

homer_anave
Contributor
Contributor

I have a family of a window with nested families of type Generic Model in it. One of the nested family type has an ElementId of 12461857 for example. I also created a new parameter of type Family Type: Generic Model named "Panel" and set another nested entity in it.

 

Now I loaded this family in a project, and placed a window using this family type. I tried to snoop at the new window's properties and went deeper to its Family Symbol and checked if the ElementId value of the parameter "Panel". I found out that the ElementId of this type is 12298607, but the nested family type set in this parameter is just the same as what it is in the family itself.

 

I created a test program that will change the value of this nested element parameter from its default to this family type's ElementId, but it would just ask me to delete them afterwards because it is unable to create the type. I did not use the SetValueString to set the value of the "Panel" parameter because it will just do nothing.

 

The questions are:

1.) Is there any basis of changing of the ElementIds at the Family level and at the parameter level?

2.) Is this ElementId value changing necessary?

3.) Where can I get the ElementIds of the all the nested elements of this family type that the parameter "Panel" is reporting (that means, without accessing the window's family document)? I tried to snoop at what's available in the Family Symbol level, but I couldn't find any. If only I could find the all the ElementIds reported by the parameter, my test program should have been successful.

 

By the way, I am using Revit 2015.

0 Likes
Accepted solutions (1)
1,077 Views
2 Replies
Replies (2)
Message 2 of 3

homer_anave
Contributor
Contributor
I guess the solution to this one is in Revit 2016.

There is a function called Family.GetFamilyTypeParameterValues that returns ids of elements with type NestedFamilyTypeReference.

I should've got more time looking for the solution.

Thank you very much!
0 Likes
Message 3 of 3

rosalesduquej
Alumni
Alumni
Accepted solution

Hi hps_anave

 

Seems to me that you are correct in regards to obtaining the Nested Family types. 

 

The following example demonstrates how to get all the family type parameter values for a FamilyType parameter of a FamilySymbol. The value for the parameter is then changed to another value. This change affects all FamilyInstances using the loaded FamilySymbol.

 

public void GetNestedFamilyTypes(FamilyInstance instance)
{
    // find one FamilyType parameter and all values applicable to it

    Parameter aTypeParam = null;
    ISet<ElementId> values = null;

    Family family = instance.Symbol.Family;

    foreach (Parameter param in instance.Symbol.Parameters)
    {

        if (param.Definition.ParameterType == ParameterType.FamilyType)
        {

            aTypeParam = param;

            values = family.GetFamilyTypeParameterValues(param.Id);

            break;
        }
    }

    if (aTypeParam == null)
    {
        TaskDialog.Show("Warning", "The selected family has no FamilyType parameter defined.");
    }
    else if (values == null)
    {
        TaskDialog.Show("Error", "A FamilyType parameter does not have any applicable values!?");
    }
    else
    {
        ElementId newValue = values.Last<ElementId>();

        if (newValue != aTypeParam.AsElementId())
        {

            using (Transaction trans = new Transaction(instance.Document, "Setting parameter value"))
            {
                trans.Start();
                aTypeParam.Set(newValue);
                trans.Commit();
            }
        }
    }
}

 

If you wish to check out the source of what I'm providing you here is the link, I hope it helps you out. 

http://help.autodesk.com/view/RVT/2016/ENU/?guid=GUID-F3F98CE6-4009-4046-BCA1-A7899CAB625C 

 

Cheers,

 



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog