Can't start a transaction in FamilyDocument?

Hi,

I’m new to Dynamo and Python, so bear with me.

I’m following Aussie Bim Guru’s “Bulk replace Revit family parameters using Dynamo!” video, and I’ve gotten to the last script, but I’m stuck. In my code when I start the transaction (2 lines down from the first for loop), Dynamo throws me an error:

TypeError: No constructor matches given arguments: (<class ‘Revit.Application.FamilyDocument’>, <class ‘str’>) [’ File “”, line 30, in \n’]

I’m thinking that it’s because I’m supplying a FamilyDocument into the input, not a Document. Is this correct? Can transactions only be instantiated in a Document? How would I go about getting the Document from a FamilyDocument?

Thanks in advance for all your help :slight_smile:

# Boilerplate text
import clr

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

clr.AddReference("RevitAPI")
import Autodesk 
from Autodesk.Revit.DB import *

# unwrap all elements to use with API
doc        = IN[0]
param_list = IN[1]
def_list   = IN[2]

param_lists_out = []
counter = 0

# Main body of code
param_list_out = []
    
for p,d in zip(param_list,def_list):
    # start a transaction
    trans = Transaction(doc,'Replace parameters')
    trans.Start()
        
    # Set the counter for namin parameters
    counter += 1
    strCount = str(counter)
    tempName = "Temporary " + strCount
        
    # Get family manager and parameter settings
    fm = doc.FamilyManager
    pg = p.Definition.ParameterGroup
    pi = p.Instance
        
    # If parameter is shared, replace with family
    # If not, then we rename it anyway
    if p.IsShared:
        p = fm.ReplaceParameter(p, tempName, pg, pi)
    else:
        fm.RenameParameter(p, tempName)
            
    # Replace family parameter with shared parameter
    shp = fm.ReplaceParameter(p, d, pg, pi)
    param_list_out.append(shp)
        
    # Close the transaction
    trans.Commit()
    TransactionManager.Instance.ForceCloseTransaction()
    
    
    
    
    
        
    
param_lists_out.append(param_list_out)
        
# Output and Changing element to Dynamo for export
# <element>.ToDSType(True), #Not created in script, mark as Revit-owned
# <element>.ToDSType(False) #Created in script, mark as non-Revit-owned

# Preparing output to Dynamo
OUT = [param_lists_out,doc]

Need to see what you’re providing for the ‘document’ input. IT may be that you need to convert it to a Revit API object instead of a Dynamo or other wrapper thereof.

2 Likes

To elaborate on Jacob’s posts, generally I have no issues passing the DB family document objects around in Revit/Dynamo. Make sure in this implementation you are just sending in one document (not many), and for testing’s sake I’d suggest running it in the open state vs using open/close doc either end if you can, that way you know the transaction is in fact the issue.

The warning does indicate it’s not getting the doc it wants, so maybe also try my document collector in Crumple as well (GetDocument), and see if that helps vs a document.current from Revit itself (or UnwrapElement() the document as Jacob suggested).

Feel free to look at my familydoc nodes in latest Crumple which are more extensive but generally a bit more complex than what the video I know you’re following there covers.

1 Like

Here is the input the script is receiving, it appears as though it’s not a DB file. Is there a place I could go to to learn more about document types? I would like to understand what exactly is going on here.

Also, I have a tangentially related issue:

I currently have 2 open files (I just opened Revit, so there is no chance there are other documents open in the background). I have a family file and a project file open. As you can see from the image above, Rhythm only sees one document, while the Crumple node sees both. I thought this might be a bug at first, but then I noticed the different document types (one is Revit.Application the other is Revit.DB). So my question would be what’s the difference?

I put the output from the Crumple Revit.GetDocuments node into the script, and that seems to have fixed the issue. I’m still curious as to why

Thank you for your help Jacob and Gavin!

For anyone in the future, here is a topic that somewhat describes my question:

For converting from Autodesk.Revit.DB.Document to Revit.Application.Document, Rhythm has nodes for this:

2 Likes