GlobalParameter.SetValue in Document

Hello everyone,
It’s possible change GlobalParameter.SetValue in Document?
I need to change global length parameters to many files without opening them.
Thanks in advance.


GlobalParameter.SetValue in Document.dyn (79.6 KB)

It is impossible to modify a file without opening it.

You could open it in the background, but that’s different.

For bulk processing I recommend setting the graph to work on the current file, and then utilize DynamoMultiPlayer from Bird Tools. Bird Tools - Dynamo Multiplayer | Revit | Autodesk App Store.

Hello,
Thanks for the reply.
Of course, I mean opening them in the background.
In this post [Global parameter set value not working] c.poupin solves it through python. . I am trying to modify his python script to change current document to document in background I can’t do it. Any suggestions?

Yes. Use the Bird Tools Multi Player which I linked above, and it will do not a single file but a list thereof, doing all the background opening for you.

Beyond that, you would have to modify the Python script to use something other than the active document.

So instead of doc = … you would need to provide a new input consisting of a list of paths, and use something like for docPath in docPaths: and then in the loop:

  1. Convert the docPath string to a model path
  2. Open the document using the model path
  3. Run the code to set the global parameter in the opened document
  4. Save the document
  5. close the document

Hi,

here is the modified script.

However, if you can, I strongly recommend , opening, making changes and closing documents within the same python script in order to free memory as you go.


import sys
import clr
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("System.Reflection")
from System.Reflection import BindingFlags

def toList(x):
    if isinstance(x, list):
        return x
    elif hasattr(x, "GetType") and x.GetType().GetInterface("IEnumerable") is not None and not isinstance(x, (str, System.String)):
        return x
    else :
        return [x]

lst_dynDoc = toList(IN[0])
lst_global_paraName = toList(IN[1])
lst_newParamValue = toList(IN[2])

for dynDoc, global_paraName, newParamValue in zip(lst_dynDoc, lst_global_paraName, lst_newParamValue):
    # convert the value
    if  isinstance(newParamValue, (float, System.Double)):
        newParamValue = DoubleParameterValue(newParamValue)
    elif  isinstance(newParamValue, (int, System.Int32, System.Int64)):
        newParamValue = IntegerParameterValue(newParamValue)
    elif  isinstance(newParamValue, ElementId):
        newParamValue = ElementIdParameterValue(newParamValue)
    else:
        newParamValue = StringParameterValue(newParamValue)
    # get the revit doc, sorry for the Private Reflection........but it's the only way from Revit.Document
    currentDoc = dynDoc.GetType().InvokeMember("InternalDocument", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Instance , None, dynDoc, None)
    print(currentDoc.Title)
    print(global_paraName)
    print(newParamValue)
    #
    # try to find Global Parameter
    glob_paraId = DB.GlobalParametersManager.FindByName(currentDoc, global_paraName )
    if glob_paraId != ElementId.InvalidElementId:
        #
        print("founded")
        glob_para = currentDoc.GetElement(glob_paraId)
        TransactionManager.Instance.EnsureInTransaction(currentDoc)
        glob_para.SetValue(newParamValue)
        TransactionManager.Instance.TransactionTaskDone()
    else:
        print("not founded")
	
OUT = lst_dynDoc
2 Likes

Hello c.poupin,
First of all, thank you very much.
The script works and set the global parameters, but I don’t know what’s happening that doesn’t allow me to save and close the file.
If I don’t use the script, it opens the file in the background, saves it and closes it. But if I use the pyhton script it doesn’t save and close.
I don’t know if it’s a problem with the script or with my PC, I use revit 23.1 with DYNAMO v.2.16.1. Do you know what the problem could be?
And a billion thanks


GlobalParameter.SetValue in Document2.dyn (58.7 KB)

Hello again,
After many tests the same problem persists regarding saving and saving.
I am writing to you again because it also gives me another problem with the value. If I use the code block node with a list created by me it works but if those same values come from project data it does not work. I tried directly, with the math round node, changing to string and then to number, and also with the extract number to string node but either does not work, only if I create the list.
Any ideas?

@knnk
you can use this node from BriMohareb Pak.
image

1 Like

Thank you so much
With this node I solve the problem. Thank you so much
I also thank c.poupin for his help and time

1 Like