Hey,
I don’t know if this is the right forum to ask questions like the one i am about to ask here so please redirect me to another forum if needed.
I use the PyRevit toolbar to run Dynamo scripts and i am just getting into coding in python for revit and want to use the PyRevit toolbar to run the scripts.
I am trying to change the value of a parameter of a family instance but i get the following error:
I think it has something to do with the opening and/or closing of a transaction.
This is the code i use:
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
import clr
clr.AddReference("RevitServices")
from RevitServices.Transactions import TransactionManager
#--------------------------------
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
#--------------------------------
TransactionManager.Instance.EnsureInTransaction(doc)
#--------------------------------
def flatten(l):
return [item for sublist in l for item in sublist]
#--------------------------------
sel = uidoc.Selection.PickObjects(Selection.ObjectType.Element, 'Choose elements')
Parameter = []
for i in sel:
SelElem = doc.GetElement(i)
Parameter.append(SelElem.GetParameters("IfcGUID")) #Parameter om uit te lezen
for i in flatten(Parameter):
#q = i.AsValueString()
#if q == None:
# i.Set("Test1")
q = i.AsString()
if q == None:
i.SetValueString("Test2")
TransactionManager.Instance.TransactionTaskDone()