Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Determine if Parameter is from a Family or Project

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
DJB_CADfx
3040 Views, 7 Replies

Determine if Parameter is from a Family or Project

I'm wondering if all parameters found on a FamilyInstance are by definition family parameters or if it is possible for some of them to be project parameters applied to the family, and if so, how do you tell the difference between the two?

 

So for example, if you use the following code to filter out just the FamilyInstance objects and look at their associated parameters:

 

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

FamilySymbol FmlySmbl;

Family Fmly;

 

foreach (FamilyInstance FmlyInst in AllFamilyInstances)

{

    FmlySmbl = FmlyInst.Symbol;

    Fmly = FmlySmbl.Family;

    

   // Look through the following ParameterSets (valid code has been left out)

   FmlyInst.Parameters;

   FmlySmbl.Parameters;

   Fmly.Parameters;

}

 

Will any of the parameters from the ParameterSets above be Project Parameters? If so, what property of the Parameter class tells you whether you have a Family Parameter or Project Parameter?

 

Conversely, if none of them can be Project Parameters, then how does one get at the Project Parameters added to a particular Family or is that not possible to do?

 

Thanks

7 REPLIES 7
Message 2 of 8
DJB_CADfx
in reply to: DJB_CADfx

Just adding to my question above, I have determined that by checking those 3 ParameterSets in the code above, I do get Project parameters, Family parameters, and Shared parameters (both Type and Instance).

 

So my question remains, how does one use the Revit Api's Parameter class to determine if the parameter is a Project parameter or Family parameter (the IsShared property tells us if it is a Shared parameter). Also, how do you tell if it is a Type or Instance parameter?

 

Thanks for the help!

Message 3 of 8
Joe.Ye
in reply to: DJB_CADfx

 

Hi djb,

 

So now the question is how to tell the difference between the project parameter and family parameter, and for a given parameter how to judge if it is a instance parameter or type parameter.

 

1. For a project parameter, there is a corresponding parameter definition binding item in the document. All the parameter binding items can be retrieved via Document.ParameterBindings property. It returns BindingMap object, the collection of all the bindings for this project, . You can loop this collection, compare the binding item's name with your target parameter name, if you cannot fine the corresponding binding name with the target parameter name, than this parameter should be family parameter. There is a binding's name is equal to your target parameter name, then it is likely to be the project parameter. (As project parameter can have the duplicate names, so here i use the likely)

 

2. From the above project parameter, you can find a binding object matching to this parameter. You can cast this Binding object to ElementBinding object. Then cast the ElementBinding object to InstanceBinding or TypeBinding. Because the InstanceBinding class and TypeBinding class derive from ElementBinding class.

 

If it can be cast to InstanceBinding object, then this parameter is for instance. Otherwise it is type parameter.

 

Hope this explains.



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Message 4 of 8
DJB_CADfx
in reply to: Joe.Ye

Thanks for the reply Joe! I had just recently learnded about the Document.ParameterBindings you mention and the fact that this is indeed the list of Project Parameters. So that is very helpful. From everything I've learned, it looks like your suggestion is the best approach. As you mentioned, not finding a match by name in this list guarantees we are dealing with a Family parameter. Finding a match means it is likely a Project parameter, but not guaranteed since you could have a parameter with the same name defined in both the project and the family.

 

I was also investigating opening the Revit Family to check its parameters using the Document.EditFamily method, but this causes a serious performance hit and lead to another question. I was wondering if you could comment on this scenario:

 

Assume you have a Revit project file with a family that contains a parameter named TEST_PARAM, and you also have a project parameter defined named TEST_PARAM that is associated with the same category as that family (so there are 2 TEST_PARAM parameters on the family, one from the family itself and one from the project). Am I correct in thinking that it is impossible to determine which one of these TEST_PARAM parameters came from the family, and which one came from the project?

 

In all of my testing, even when opening the Family Project file directly, I've found no way to correctly associate the two other than by name, which is not reliable since the name can be identical across the parameters of the project and family. In my testing, the IDs of the parameters are not the same when comparing the FamilyParameter objects from the family file with Parameter objects of the same name from the project file. Is this true?

 

Thanks for your help!

 

Message 5 of 8
Joe.Ye
in reply to: DJB_CADfx

 

If a family instance contains Project Parameter namedTEST_PARAM, and also the family parameter named TEST_PARAM.   Still we can use the parameter's host Group and the parameter storage type to identify their difference.

 

However if both the parameter group and the storage type are identical, no more feature can tell the different between parameter which is the project one and which is the family parameter. 

 

Revit didn't provide the mechnism to prevent identical parameter names, so please avoid adding the duplicate parameter name for the same category via API. 

 

 



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Message 6 of 8
DJB_CADfx
in reply to: Joe.Ye

Joe,

 

Thanks again for your input. We were tasked with creating a utility to locate problems in parameters (duplicate names or missing parameters) and display them to the user. We don't ever create the duplicate names ourselves, but users sometimes do, so this tool is to help them locate the problems so they can fix them.

 

The tool is designed to do the following:

  1. Display all unique (non-built-in) parameters across a given category (listed alphabetically) including duplicates (that have different IDs)
  2. For each parameter, list all unique Families belonging to that Category
  3. Under each Family column display a "P" or "F" if that family contains that parameter ("P" if the parameter came from the Project and "F" if it came from the Family)
  4. The user can then quickly locate duplicates in the list and the "P" or "F" tells them whether they need to fix the parameter in the Family or the Project file.
  5. Also, they can quickly see if certain families are missing a parameter that the others have and decide if that is  by design or a mistake that needs to be resolved.

Thanks for the help you provided, it is much appreciated!

Message 7 of 8
metier3
in reply to: DJB_CADfx

Hello,

 

I have found a way the works to acheive this.

 

This is a 4 step process:

  1. Check if the Parameter is Shared, if yes then it is a share parameter
  2. Check if the Parameter is Builtin, if yes then it is builtin
  3. Check the Scheduleable parameters (a function is 2014 onwards) to see if the parameters id is in here, if yes and it is not a shared or builtin parameter then it must be a project parameter?
  4. Else it is a family paramter...

It seems to work. Not sure why a parameter doesnt have a IsProject variable....

 

Regards

 

Chris Mckeown

Message 8 of 8
psmith
in reply to: metier3

Hi Chris,

How are you checking if it's Builtin?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community