Adjusting Python node for multiple families as input (sublists)

Hi,

Can anybody help me with adjusting a (python) node from Crumple Package (@GavinCrump)?
The node is ‘ParameterReplaceShared’ and the total script is from this tutorial from him:

I’m having to replace all of my shared parameters.

I have the script working with one family at the time.
Now I want to adjust the script for batch processing all of my families.

I’m running into a problem with the node ParameterReplaceShared where it reconizes my sublists input (seperate revit families) but the output, i think, is still using the ‘current document’ i have opened.

I believe the python script within that node isn’t written for multiple entries and/or working with sublists.

# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au

#Credit to Joshua Budarick for his assistance with this workflow!
# https://www.linkedin.com/in/joshua-budarick-9bb50b4b/

# Boilerplate text
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

#Inputdoc : Part of script by Andreas Dieckmann
inputdoc = IN[0]

if inputdoc == None:
    doc = DocumentManager.Instance.CurrentDBDocument
elif inputdoc.GetType().ToString() == "Autodesk.Revit.DB.Document":
    doc = inputdoc
else:
	doc = DocumentManager.Instance.CurrentDBDocument

# Functions
def uwlist(input):
    result = input if isinstance(input, list) else [input]
    return UnwrapElement(input)

#unwrap all elements to use with API
params = uwlist(IN[1])
names  = uwlist(IN[2])

params_new, names_new = [],[]

# Collect values
if doc.IsFamilyDocument:

	# "Start" the transaction
	TransactionManager.Instance.EnsureInTransaction(doc)
	
	for p,n in zip(params, names):
		try:
			new = doc.FamilyManager.ReplaceParameter(p, n, p.Definition.ParameterGroup, p.IsInstance)
			params_new.append(new)
			names_new.append(n)
		except:
			params_new.append(None)
			names_new.append(None)

	# "End" the transaction
	TransactionManager.Instance.TransactionTaskDone()

	OUT = [params_new, names]
	
else:
	OUT = ["Document is not a family.",""]

The problem I’m having:

Generally to solve situations like this I turn to Python vs using my custom nodes, many of them are designed to work across one document currently.

This seems to work for replacing shared parameters with others in multiple families. The new parameters cannot be in the document as well or it will fail (I haven’t added all the try/except safeguards), and they must exist by name in the active shared parameter file.

I do not have time to customize it to fringe cases for people, but hopefully it’s helpful anyway. If you’re not familiar with Python these types of workflows are usually a good time to begin learning it as well.

# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au

# Boilerplate text
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

#Inputdoc : Part of script by Andreas Dieckmann
docs = IN[0]

#unwrap all elements to use with API
param_lists = IN[1]
names_lists = IN[2]
def_lists = IN[3]

param_lists_out = []

# Collect values
for doc,plst,nlst,dlst in zip(docs,param_lists,names_lists, def_lists):
	
	param_list_out = []
	
	for p,n,d in zip(plst,nlst,dlst):
		
		# Start a transaction
		trans = Transaction(doc, 'replace parameter 1')
		trans.Start()
		
		# Replace parameter
		fam = doc.FamilyManager.ReplaceParameter(p, n, p.Definition.ParameterGroup, p.IsInstance)
		shp = doc.FamilyManager.ReplaceParameter(fam, d, fam.Definition.ParameterGroup, fam.IsInstance)
		
		param_list_out.append(shp)
		
		# Close a transaction
		trans.Commit()
		TransactionManager.Instance.ForceCloseTransaction()

	param_lists_out.append(param_list_out)

OUT = param_lists_out

Bulk replace paramameters (shared to shared).dyn (51.1 KB)

Sample files here:

@GavinCrump

Thanks so much, I really appreciate this!
I’ve made it work with my library and i’m currently replacing shared parameters in 600+ rfa files.

1 Like

Just adding that the video for this is now available, hopefully helps people facing a similar challenge in understanding the approach I took:

@jeroen.reynders

1 Like