Revit API

Reply
djb
Active Member
djb
Posts: 8
Registered: ‎08-25-2011
Message 1 of 5 (1,157 Views)
Accepted Solution

Parameters From Family vs. FamilyInstance

1157 Views, 4 Replies
01-30-2013 03:12 PM

I was hoping someone more knowledgable than I could explain what I am seeing with the 2 code snippets below. The first grabs a colletion of Family type objects with a collector, while the second grabs a collection of FamilyInstance type objects.

 

Questions:

  1. Why is the list of parameters on the family objects completely different from the parameters on the FamilyInstances? I guess I assumed, a FamilyInstance was an instance of a family object, so it would contain the same parameters with all values specific to that instance, but that is clearly not the case. In my sample document, they share no parameters in common at all.
  2. The names of Family objects vs. FamilyInstance objects also are all different, so what is the relationship there?

Code Snippet 1

ElementClassFilter FamilyFilter = new ElementClassFilter(typeof(Family));
FilteredElementCollector FamilyCollector = new FilteredElementCollector(RvtDoc);
ICollection<Element> AllFamilies = FamilyCollector.WherePasses(FamilyFilter).ToElements();
foreach (Family Fmly in AllFamilies)
{
    string FamilyName = Fmly.Name;
    foreach (Parameter Param in Fmly.Parameters)
    {
        string ParamName = Param.Definition.Name;
    }
}

 

 Code Snippet 2

ElementClassFilter FamilyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance));
FilteredElementCollector FamilyInstanceCollector = new FilteredElementCollector(RvtDoc);
ICollection<Element> AllFamilyInstances = FamilyInstanceCollector.WherePasses(FamilyInstanceFilter).ToElements();
foreach (FamilyInstance FmlyInst in AllFamilyInstances)
{
    string FamilyInstanceName = FmlyInst.Name;
    foreach (Parameter Param in FmlyInst.Parameters)
    {
        string ParamName = Param.Definition.Name;
    }
}

 

The ultimate goal was to build a list of all parameters under each family in the Revit Document, but the differences I've encountered between Family objects and FamilyInstance objects has me fairly confused as to just how all of this works!


Thanks for any insight you can provide!

 

Distinguished Contributor
ollikat
Posts: 148
Registered: ‎04-01-2011
Message 2 of 5 (1,142 Views)

Re: Parameters From Family vs. FamilyInstance

01-31-2013 01:19 AM in reply to: djb

The Revit API is working just as you have observed. The idea is that you can have either family parameters, type parameters or instance parameters. Those can be accessed (directly) only trough corresponding API object (Family, Type or FamilyInstance).

 

If you want to access for example type parameters trough instance, you have to use FamilyInstance.Symbol property to get the type element, which in turns has access to those parameters.

 

I would also recomend to get familiarise your self with the lookup/snooby add-in whick can be found from SDK. From there you can observe the same that I explained above.

djb
Active Member
djb
Posts: 8
Registered: ‎08-25-2011
Message 3 of 5 (1,131 Views)

Re: Parameters From Family vs. FamilyInstance

01-31-2013 10:32 AM in reply to: ollikat

Thanks for your input.

 

I'm mainly interested in the Shared Parameters. So if I want to collect all shared parameters on families in a revit document, am I correct in thinking that it is necessary to look at the parameters found on both the Family type elements and FamilyInstance type elements in the document. Then check all of those paramerers to find all that have IsShared set to true?

 

Actually, there would be a problem with this because it would get parameters from all Family objects. I only want the ones that have an instance in the document. Therefore, I'm guessing I need to do only the FamilyInstance search and from each FamilyInstance obtain its associated Family type to get its parameters as well.

 

However, I'm not seeing any way to go from the FamilyInstance object to its associated Family object. Is there a method in the API for doing this?

 

Distinguished Contributor
ollikat
Posts: 148
Registered: ‎04-01-2011
Message 4 of 5 (1,122 Views)

Re: Parameters From Family vs. FamilyInstance

01-31-2013 09:46 PM in reply to: djb

That's the way it goes IMO.

 

And there is a way to get the whole chain: FamilyInstance -> FamilySymbol (type) -> Family

 

From FamilyInstance object it is "Symbol" property. That gives you FamilySymbol object.

 

Furthermore from FamilySymbol you can get "Family" property which gives you Family object.

 

So there are these three levels which can contain shared parameters. Hope this helps.

djb
Active Member
djb
Posts: 8
Registered: ‎08-25-2011
Message 5 of 5 (1,110 Views)

Re: Parameters From Family vs. FamilyInstance

02-01-2013 07:00 AM in reply to: ollikat

Many thanks Ollikat, I think I get it now! Let me summarize my understanding for any future viewers of this post. If I have anything incorrectly stated, please let me know:

 

  1. Obtaining all parameters from an instance of a family requires checking the parameters of 3 objects, FamilyInstance, FamilySymbol & Family.
  2. FamilyInstance objects contain Instance parameters.
  3. FamilySymbol objects contain Type parameters.
  4. Family objects also contain Type parameters.
  5. Any of these parameters can be Shared Parameters, one must check the IsShared property to determine.
  6. The following code snippet would provide the full list of parameters associated with the Families in use within a given Revit document:

 Code Snippet

ElementClassFilter FamilyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance));
FilteredElementCollector FamilyInstanceCollector = new FilteredElementCollector(RvtDoc);
ICollection<Element> AllFamilyInstances = FamilyInstanceCollector.WherePasses(FamilyInstanceFilter).ToElements();

List<string> ParamLst = new List<string>();

FamilySymbol FmlySmbl;

Family Fmly;

 

foreach (FamilyInstance FmlyInst in AllFamilyInstances)
{
    FmlySmbl = FmlyInst.Symbol;

    Fmly = FmlySmbl.Family;

 

    // Add Instance Parameter names to list
    foreach (Parameter Param in FmlyInst.Parameters)
    {
        ParamLst.Add = Param.Definition.Name;
    }

 

    // Add Type Parameter names to list
    foreach (Parameter Param in FmlySmbl.Parameters)
    {
        ParamLst.Add = Param.Definition.Name;
    }


    // Add Family Type Parameter names to list
    foreach (Parameter Param in Fmly.Parameters)
    {
        ParamLst.Add = Param.Definition.Name;
    }

}

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Revit Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Revit helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Revit

Twitter

Facebook

Blogs

Youtube