Checking if a FamilyParameter is used on other FamilyParameter's formulas

Checking if a FamilyParameter is used on other FamilyParameter's formulas

JoaoPalma
Participant Participant
736 Views
9 Replies
Message 1 of 10

Checking if a FamilyParameter is used on other FamilyParameter's formulas

JoaoPalma
Participant
Participant

Good afternoon,

As the title says, is there any way to check if a given FamilyParameter is being used on other formulas?

the only way i can think of is to retrieve every formula in the family and check if these formulas contain the parameter name, but this could give bad results in case, for example, there is a "Parameter" and a "Parameter1". "Parameter1" contains "Parameter" and retrieving this is not the desired result.

the other way is to retrieve all formulas, delete/rename the parameter, check which formulas changed and then roll back the transaction, but this wont work for builtin parameters since they cant be renamed/deleted.

is there any property (like .AssociatedParameters or .IsDeterminedByFormula) which can retrieve a ParameterSet with all the parameters that, in their formulas, use a certain FamilyParameter?

 

Thank you for your attention

0 Likes
Accepted solutions (1)
737 Views
9 Replies
Replies (9)
Message 2 of 10

RPTHOMAS108
Mentor
Mentor

Yes not easy, similar to your second approach is probably the only way.

 

I don't understand your example regarding Parameter and Parameter1, if Parameter1 contains Parameter then Parameter is used by Parameter1. The real issue is parameter names with spaces! i.e. 'Parameter 1' can't be distinguished from 'Parameter' via simple comparison without RegEx.

 

However my approach would be to rename all parameters with a GUID, regenerate and see what formulas contain which GUIDs. Remembering that Parameter names can't start with a number but GUIDs can (so add an alphabetical prefix).

 

Regarding built-in parameters, yes they can't be renamed but at the same time you can't have two family parameters with the same name (so you know the names are reliable to look for in formulas to that extent). Likewise you can't use keywords like 'If' and 'Roundup' as parameter names. 

 

0 Likes
Message 3 of 10

JoaoPalma
Participant
Participant
Thank you for your reply.
i dont think i explained myself too well, the first example was about using the method .Contains for strings. so if a parameter is named "Parameter1" and i'm trying to see if a formula contains the name "Parameter", it will return formulas that have "Parameter1" and "Parameter".
My main issue is with BuiltIn Parameters, since i cant rename them and revit allows almost every character to be used in the names of parameters. This wouldnt be a issue if all the parameters inside the formulas were contained inside square brackets, but unfortunatelly only the ones with mathematical symbols require them.
Anyways i was just wondering if there was any fast way of doing it using the API, since i could be missing something on the API documents. I think this should be implemented in the future similarly to .AssociatedParameters, which returns a ParameterSet of all associated parameters. that would be great, because currently it is very hard to replace a parameter with another without knowing exactly where this parameter is being used.
0 Likes
Message 4 of 10

RPTHOMAS108
Mentor
Mentor

There is no API method for this as far as I'm aware.

 

Yes you can have parameter names containing mathematical operators but you'll likely not find a BIP name containing such (they leave such bad practice to be a user choice in this respect).

 

If you use the GUID renaming approach then the mathematical operators in the user defined parameter names are not an issue because they are temporarily renamed out and you look to match the GUID in the formula.

 

I would probably not use a GUID just rename with numbers i.e. _1, _2....and match that, the only reason for the GUID was if an existing parameter was already named _1 or _2...

0 Likes
Message 5 of 10

JoaoPalma
Participant
Participant
Yes, i think the problem for non-BIP parameters is solvable and i appreciate your solution. The problem is with the BIP because even if they dont contain mathematical operators, if someone names a parameter "Width + Height + Length" and im looking for the BIP "Width", im going to have to create a ton of rules to check exactly which parameter the formula is using. (have to retrieve all family parameters, filter the ones that have "Width" and check if the formula has squared brackets around them or not)

i was just trying to avoid doing all that, in case the API had an easier way of doing it, but unfortunately it seems that im out of luck. Anyways i appreciated the replies, thank you very much.
0 Likes
Message 6 of 10

RPTHOMAS108
Mentor
Mentor
Accepted solution

If someone names their parameter 'Width + Height + Length' then it is renamed '_GUID1' before looking in the formula (that is what it is now known as in the formula). The BIP 'Width' is still known as 'Width' in the formula and there can't be two parameters with the same name BIP or otherwise.

 

Just rename all the user parameters (in one step regardless of their existing name) regenerate and check their new known names in the formulas. The names for the BIPs can remain as they were and they will not be confused with a user parameter renamed in the form '_GUID1'.

Message 7 of 10

JoaoPalma
Participant
Participant
oh, i didnt think about renaming all of them. thats a good approach. i will explore it further, thank you for your suggestion!
0 Likes
Message 8 of 10

RPTHOMAS108
Mentor
Mentor

I've used this approach in the past. The complication is you can't rename the shared parameters you have to replace them with temporary non-shared ones (the last two FamilyManager.ReplaceParameter overloads).

 

I recall that it checks the formulas after each parameter replacement so if there isn't a regeneration after replacing the first parameter then when a further parameter is replaced that refers to that first replaced parameter then an exception will be thrown because it is checking based on what the parameter was called in the formula before it was replaced and not finding it (name no longer exists). I think you'll either have to regenerate after each replacement or you could keep track of the names replaced since last regeneration and regenerate if the next formula refers to an old name that was replaced after the last regeneration. The latter approach leads back to the original problem so is probably not practical.

0 Likes
Message 9 of 10

JoaoPalma
Participant
Participant

thank you so much for this information, its gonna avoid some future headaches for sure!
May i ask you one unrelated question? (unrelated to current topic but related to the API)
when i reload a family using .LoadFamilySymbol method, ive noticed that it doesnt update the FamilyManager.
lets say i load half the symbols from a family and then i load again the other half. if i use Family.GetFamilySymbolIds, it shows all the symbols but if i access the FamilyManager and do FamilyManager.Types, it only shows the prior FamilyTypes from the first load. I've noticed that through the revit UI, if i simply click "Edit Family" and then close, it updates it. im having a hard time updating it through the API.
I've tried to Regenerate and stuff like that but it wont work. the only thing that works is if i call .SaveAs and save the family with a different name (i think it kinda does something similar as opening and closing the family through the UI).

0 Likes
Message 10 of 10

RPTHOMAS108
Mentor
Mentor

Are the types you load defined in the family itself or the type catalogue? I believe the FamilyManger may only list those defined in the family.

 

When you load a family in the project and add a type from the catalogue it adds that type to the family in the project. So when you then edit the family or save it elsewhere it then has the type defined in the family.

0 Likes