Getting a Parameter After It Has Been Set

I have a complex set of equations and lookup tables in a family to calculate my air pressure drop (APD) parameter, which is a function of Air Flow. Instead of remaking those equations and tables in python (and having to update them in two places), I was hoping to place a family, set the air flow parameter, and then read the updated APD parameter.

The problem I’m having is that the APD parameter does not update based on the Air Flow Parameter, it seems, until the whole graph is done running. I would like get the APD inside of one code block so that I can make future decisions based on that value.

I have a feeling that this is a TransactionManager Problem, but I don’t know enough about the API to know for sure. I’ve tried setting and getting in different TransactionManager.Instance, but to no avail.

Any help would be greatly appreciated.

Thanks!

#ImportDynamoCoreNodes
import clr
clr.AddReference('ProtoGeometry')
clr.AddReference('RevitAPI') 
import Autodesk
clr.AddReference('RevitAPIUI')

from Autodesk.DesignScript.Geometry import *
import Autodesk.Revit.DB as DB 

# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit

# Import Revit elements
from Revit.Elements import *

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


#Get Current Document, Application, and UI document for later use.
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#get all family symbols that are in the OST_MechanicalEquipmentCategory
collector = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_MechanicalEquipment).OfClass(DB.FamilySymbol)
famtypeitr = collector.GetElementIdIterator()
    
HWCVAVFamilyName = "M-EQUIP-VAV-TITUS-DESV HWC" 
HWCVAVFamilyTypeName = "DESV-07_2 Row"

#Cycle through all items in collector, get the element Name (Family Type),  
for item in famtypeitr:
    famsymb = doc.GetElement(item)
    
    TypeNameOfCurrentIterationOfFamily = DB.Element.Name.__get__(famsymb) 

    #If the family symbol is == to the family symbol and the type names match what I'm looking for:
    if famsymb.Family.Name == HWCVAVFamilyName and HWCVAVFamilyTypeName == TypeNameOfCurrentIterationOfFamily:
        unwrappedfamsymb = UnwrapElement(famsymb)
        
    
#Need to do this in case document doesn't know the family is in it. 
if unwrappedfamsymb.IsActive == False:
    unwrappedfamsymb.Activate()
    doc.Regenerate()

#convert insertion point to Revit units

insertionPointXYZ = DB.XYZ(0,0,0)
    
TransactionManager.Instance.EnsureInTransaction(doc)
#Insert family and get elementID, then element, so that I can manipulate parameters. 
familyInst = doc.Create.NewFamilyInstance(insertionPointXYZ, unwrappedfamsymb, DB.Structure.StructuralType.NonStructural)

#Get the regular family parameters to SET:
VAVMaxCFMForConditioningParam = familyInst.LookupParameter('Actual Supply Air Flow')

#For Now SET PARAMETERS:
VAVMaxCFMForConditioningParam.Set(DB.UnitUtils.ConvertToInternalUnits(500, DB.DisplayUnitType.DUT_CUBIC_FEET_PER_MINUTE))
TransactionManager.Instance.TransactionTaskDone()

#The family should be inserted, and the parameter should be updated.  Now to get the resulting parameter that is calculated from the VAVMaxCFMForConditioningParam-'Actual Supply Air Flow' 

#Trial 1) - This gets the original Parameter (Not Updated Per VAVMaxCFMForConditioningParam)
#VAVAPDParam = familyInst.LookupParameter('VAV HWC MAX APD (IN W.C.)')
#VAVAPD = DB.UnitUtils.ConvertFromInternalUnits(familyInst.get_Parameter(VAVAPDParam.GUID).AsDouble(), DB.DisplayUnitType.DUT_INCHES_OF_WATER)
#/Trial 1)

#Trial 2) Start New Transaction, this still gets the UNupdated parameter. 
#TransactionManager.Instance.EnsureInTransaction(doc)
#VAVAPDParam = familyInst.LookupParameter('VAV HWC MAX APD (IN W.C.)')
#VAVAPD = DB.UnitUtils.ConvertFromInternalUnits(familyInst.get_Parameter(VAVAPDParam.GUID).AsDouble(), DB.DisplayUnitType.DUT_INCHES_OF_WATER)
#TransactionManager.Instance.TransactionTaskDone()
#/Trial 2)

#Trial 3) Get Element again to allow it to update, this still gets the UNupdated parameter. 
#elementID = familyInst.Id
#element = doc.GetElement(elementID)
#VAVAPDParam = element.LookupParameter('VAV HWC MAX APD (IN W.C.)')
#VAVAPD = DB.UnitUtils.ConvertFromInternalUnits(element.get_Parameter(VAVAPDParam.GUID).AsDouble(), DB.DisplayUnitType.DUT_INCHES_OF_WATER)
#/Trial 3) 

#Trial 4) Try in new tranaction, this still gets the UNupdated parameter. 
TransactionManager.Instance.EnsureInTransaction(doc)
elementID = familyInst.Id
element = doc.GetElement(elementID)
VAVAPDParam = element.LookupParameter('VAV HWC MAX APD (IN W.C.)')
VAVAPD = DB.UnitUtils.ConvertFromInternalUnits(element.get_Parameter(VAVAPDParam.GUID).AsDouble(), DB.DisplayUnitType.DUT_INCHES_OF_WATER)
TransactionManager.Instance.TransactionTaskDone()
#/Trial 4) 

#Assign your output to the OUT variable. 
OUT = VAVAPD

Whoops, nevermind.

Replace Line 67 with TransactionManager.Instance.ForceCloseTransaction()

Fixed the problem.