Cannot set parameter in linked Revit files -

Hello

I created a script that sets any room parameter in linked Revit files. The script works perfect, you run it on a “master model” with several linked files, select one of them and set a parameter name you would like to change - I am transfering name of the level where the room is located to one of its instance parameters. Dynamo opens the project on a background, set the parameters and loads the project back to the master. The script works perfect, when I test it with a blank project based on AC template.

The problem is that when I run the script on a certain project (it is very old project that is in the process many years - many versions of Revit), the link file unloads, the parameters are set, but it crashes when Dynamo wants to load the project back to the master model.
image

I figured out, that the problem might be in Third Party Updater. The Journal file says that the Third Party Updater ‘Revit: ObjectNumberingUpdater’ has been unregistered. I do not have any addins installed, and I believe that the problem might be, that someone in the past installed some addin to Revit, used it on this project, and then uninstall it. (Tested on revit 2022 and 2023)

I attach the journal file and also the Python script that does the job.

Anyone has any idea? Maybe it is possibble to figure this out with Python. Thank you for all the help.

Lucie


import clr

clr.AddReference('System')
from System.Collections.Generic import List

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)


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

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
app = DocumentManager.Instance.CurrentUIApplication.Application

link = UnwrapElement(IN[0])
parname = IN[1]
val = IN[2]


linkPath = link.GetLinkDocument().PathName
linkType = doc.GetElement(link.GetTypeId())

TransactionManager.Instance.ForceCloseTransaction()
linkType.Unload(None)

linkDoc = app.OpenDocumentFile(linkPath)
el = FilteredElementCollector(linkDoc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()

TransactionManager.Instance.EnsureInTransaction(linkDoc)
for e,v in zip(el,val):
        e.LookupParameter(parname).Set(v)

TransactionManager.Instance.TransactionTaskDone()
TransactionManager.Instance.ForceCloseTransaction()

linkDoc.Close()
linkType.Reload()

OUT = linkDoc

journal.0003.txt (271.7 KB)

1 Like

This updated isn’t actually third party as in add-in, but a separate component of Revit.

Out of curiosity, if you manually do the process does it work?

Hello Jacob,
yes, when I do it Manually it works.
Do you have any idea what kind of seperate component it might be and how can I solve it? Thank you

L.

There is no indication that an external component is the issue - those 3rd party components unregistering is part of the crash process to keep things secure on the next launch.

I’d have to rebuild your dataset to run the code, which is time prohibitive so I can’t confirm, but this feels like a transaction management issue, in that you’re modifying the link type outside of a transaction twice. Unloading and loading without any changes is apt to work well, but once something has to update (which is the case as you’re modifying the link) I think you’d want a transaction on the host to unload, a transaction on the link to modify it, and a transaction on the host to reload.

Hi Jacob,

even when I change the transactions, the problem remains. But I might have some mistake in handling transtactions. Do you think that there is any other way how to solve it?


import clr
# Import List ( ICollection(ElementId) = List[ElementId]() )
clr.AddReference('System')
from System.Collections.Generic import List

# Import Revit API
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

# Import ToDSType(bool) extension method
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
app = DocumentManager.Instance.CurrentUIApplication.Application

link = UnwrapElement(IN[0])
parname = IN[1]
val = IN[2]
#comment = IN[1]


TransactionManager.Instance.EnsureInTransaction(doc)

linkPath = link.GetLinkDocument().PathName
linkType = doc.GetElement(link.GetTypeId())

TransactionManager.Instance.TransactionTaskDone()
TransactionManager.Instance.ForceCloseTransaction()


linkType.Unload(None)


linkDoc = app.OpenDocumentFile(linkPath)
el = FilteredElementCollector(linkDoc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()

TransactionManager.Instance.EnsureInTransaction(linkDoc)

for e,v in zip(el,val):
        e.LookupParameter(parname).Set(v)
       
TransactionManager.Instance.TransactionTaskDone()
TransactionManager.Instance.ForceCloseTransaction()

linkDoc.Close()

TransactionManager.Instance.EnsureInTransaction(doc)
TransactionManager.Instance.TransactionTaskDone()
TransactionManager.Instance.ForceCloseTransaction()

linkType.Reload()



OUT = linkDoc

Thank you
Lucie

Try using the actual transaction methods, not the transaction manager. Something along these lines:

t = Transaction(doc, 'Name')
#unload here
t.Commit()
if not t.HasEnded:
    t.Dispose()

Hello Jacob,

I would like to let you know, that I changed the code (I used actual transaction methods) and I get the same error.


import clr
# Import List ( ICollection(ElementId) = List[ElementId]() )
clr.AddReference('System')
from System.Collections.Generic import List

# Import Revit API
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

# Import ToDSType(bool) extension method
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
app = DocumentManager.Instance.CurrentUIApplication.Application

link = UnwrapElement(IN[0])
parname = IN[1]
val = IN[2]

TransactionManager.Instance.ForceCloseTransaction()

linkPath = link.GetLinkDocument().PathName
linkType = doc.GetElement(link.GetTypeId())

linkType.Unload(None)

t = Transaction(doc, 'Name')
#unload here


t.Start()

t.Commit()
if not t.HasEnded:
    t.Dispose()

linkDoc = app.OpenDocumentFile(linkPath)
el = FilteredElementCollector(linkDoc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()


t = Transaction(linkDoc, 'link')
t.Start()
for e,v in zip(el,val):
        e.LookupParameter(parname).Set(v)
       
t.Commit()
if not t.HasEnded:
    t.Dispose()

linkDoc.Close()

linkType.Reload()



OUT = linkDoc

Hi, @Lucy_Lastparametrics!

Look into “SetParameterByName in Document” python code from Genuis Loci package. I’ve used it, it worked correctly.

1 Like