FamilyDoc.AddsharedParameter returns null

I’m trying to add all our parameters to a family for some testing. When I run this script it does not add any parameters.

@crapai

Are you try to set all the parameters from the file to the family s? Than change the lacing to longest.
The instance need a 1/0 as input

The node expects a list of background opened family documents as well as equal length lists of parameter definitions, groups and booleans. It then takes those lists and creates those parameters in each document. All those family documents need to be closed when the script is run prior. No lacing or levels needed, just matching list lengths.

I have a video here on how it works:

1 Like

Thanks, I had a list count and cycle to make them the same length but it still wasn’t working. Your comment on needed multiple families made it work. I just copied the family and added the count and cycle back into the group and instance and it worked.

1 Like

Hi Gavin,
I’m trying to add some shared parameter to some family doc in a folder, and this works fine…
but…
I would also to add a formula to those parameters.
I’ve added a column to my excle file and modify the code block as:
name = data[0];
bipg = data[2];
inst = data[3] == “Yes”;
formula = data[4];

Then, I’ve tryed to modify the node FamilyDocAddSharedParameter adding an input
IN[4] as formula: string;

the python script modified is:

#detect if document is not set
if IN[0] == None:
docs = [DocumentManager.Instance.CurrentDBDocument]
else:
docs = tolist(IN[0])

#unwrap all elements to use with API
definitions = tolist(IN[1])
bipgs = tolist(IN[2])
isInstance = tolist(IN[3])
#addformula
formula = tolist(IN[4])
outcomes =

Collect values

for doc in docs:

if doc.IsFamilyDocument:
	
	outcome = []
	
	# "Start" the transaction
	TransactionManager.Instance.EnsureInTransaction(doc)

	for d,b,i in zip(definitions, bipgs, isInstance):
		try:
			new = doc.FamilyManager.AddParameter(d,b,i)
			doc.FamilyManager.SetFormula(d,formula)
			outcome.append(new)
		except:
			outcome.append("Parameter not added.")
	# "End" the transaction
	TransactionManager.Instance.ForceCloseTransaction()

else:
	outcome = "Document is not a family document."

	
outcomes.append(outcome)

OUT = outcomes

Please I’m not an expert and probably I’ve done something wrong… this doesn’t work… :frowning:

Haven’t got time to read/shoot all the Python, but if you’ve got loop structure correct then the most likely error is the formula isn’t in a structure that suits Revit. E.g. if it’s text it needs to also have double apostrophes around it as a string.

You will also need to ensure your formula is an object and not a list. Currently you’re just referencing formula as a variable but not iterating with it similarly to the d,b,i variables. Make sure you are working with 1 to 1 object relationship between parameter and formula.