Traceback FamilyDocAddSharedParameter

Hi all,

Is it possible to get a Traceback with information why the parameter isn’t add?

You would need to modify the try / except statement within the node to give exception information in lieu of “Param not added”.

@GavinCrump

1 Like

The most common reasons for this are that the parameter already exists in the family or one of the settings being applied in the process will not be acceptable. If you lift out the python in the node and get rid of the try/except then you’ll see the specific reason why.

Also make sure your parameters are being found by name prior, if the node fails to get a relevant exdef it will just default to -1 index which when indexed in Python gets the last exdef each time. I seem to recall my script and video I show it in use a code block to index the matching exdef by name so that’ll be the reason if so - it’s a cleaner outcome as otherwise the getitematindex would return a null and the script would hit issues.

# 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

# Functions
def tolist(input):
    result = input if isinstance(input, list) else [input]
    return result
    
def uwlist(input):
    result = input if isinstance(input, list) else [input]
    return UnwrapElement(result)
    
#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])

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)
				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
1 Like

Yes thanks for the reminder :slight_smile:

1 Like

The result:

Thanks @GavinCrump and @SeanP

# 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
import traceback

# Functions
def tolist(input):
    result = input if isinstance(input, list) else [input]
    return result
    
def uwlist(input):
    result = input if isinstance(input, list) else [input]
    return UnwrapElement(result)
    
#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])

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)
				outcome.append(new)
			except:
				outcome.append(traceback.format_exc())

		# "End" the transaction
		TransactionManager.Instance.ForceCloseTransaction()
	
	else:
		outcome = "Document is not a family document."
	
	outcomes.append(outcome)
	
OUT = outcomes

Yep looks like it’s the -1 index thing in that case. Most common cause is typos or case sensitivity when finding matching parameters in the step before.