Oded_F
(Oded Fuhrmann)
April 30, 2024, 12:26am
1
Not sure this is the correct category, but…
In PowerShell:
$Env:VariableName=“Bluh”
And the following:
echo $Env:VariableName
Yields
Bluh
Yet from pyrevit:
value = os.getenv(‘VariableName’)
print(value)
prints nothing.
I asked chatgpt but it was not able to solve this so falling back to my fellow humans.
Any suggestions?
Jean-Marc
(Jean-Marc Couffin)
April 30, 2024, 7:52am
2
I will reply about what I know is available by default within pyRevit:
from the pyrevit.coreutils envars module
from pyrevit.coreutils import envvars
envvars.set_pyrevit_env_var(‘MY_SCRIPT_STATUS’, True)
envvars.set_pyrevit_env_var(‘MY_SCRIPT_CONFIG’, {‘someconfig’: True})
envvars.set_pyrevit_env_var(‘vn2’, ‘blah blah’)
print(envvars.get_pyrevit_env_vars())
print(envvars.get_pyrevit_env_var(‘MY_SCRIPT_STATUS’))
print(envvars.get_pyrevit_env_var(‘MY_SCRIPT_CONFIG’))
print(envvars.get_pyrevit_env_var(‘vn2’))
from pyrevit.coreutils import envvars
envvars.set_pyrevit_env_var('MY_SCRIPT_STATUS', True)
envvars.set_pyrevit_env_var('MY_SCRIPT_CONFIG', {'someconfig': True})
envvars.set_pyrevit_env_var('vn2', 'bzrpjkerpobgemrlkgb')
# print(envvars.get_pyrevit_env_vars())
print(envvars.get_pyrevit_env_var('MY_SCRIPT_STATUS'))
print(envvars.get_pyrevit_env_var('MY_SCRIPT_CONFIG'))
print(envvars.get_pyrevit_env_var('vn2'))
Oded_F
(Oded Fuhrmann)
April 30, 2024, 4:09pm
3
Thank you sir, but nothing.
How do you set these variables value (not programmatically but from outside Revit, from cmd line?
Here is what I did and the (None ) response from PyRevit:
print(envvars.get_pyrevit_env_vars())
print(envvars.get_pyrevit_env_var('VariableName'))
{‘PYREVIT_TELEMETRYINCLUDEHOOKS’: False, ‘PYREVIT_REFEDASSMS’: ‘C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsFormsIntegration\v4.0_4.0.0.0__31bf3856ad364e35\WindowsFormsIntegration.dll;C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll;C:\Program Files\Autodesk\Revit 2024\RevitAPI.dll;C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\pyRevitLabs.PyRevit.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\engines\IPY277\pyRevitLoader.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\pyRevitLabs.PyRevit.Runtime.Shared.dll;C:\Program Files\Autodesk\Revit 2024\UIFramework.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\pyRevitLabs.Emojis.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\engines\IPY277\Microsoft.Scripting.dll;C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll;C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\pyRevitLabs.Json.dll;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Web.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\pyRevitLabs.Common.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\engines\IPY277\IronPython.dll;C:\Program Files\Autodesk\Revit 2024\Xceed.Wpf.AvalonDock.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\pyRevitLabs.NLog.dll;C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll;C:\Program Files\Autodesk\Revit 2024\RevitAPIUI.dll;C:\Program Files\Autodesk\Revit 2024\AdWindows.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\engines\IPY277\IronPython.Modules.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\pyRevitLabs.MahAppsMetro.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\pyRevitLabs.CommonWPF.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\engines\IPY277\Microsoft.Dynamic.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\pyRevitLabs.TargetApps.Revit.dll;C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.dll;C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll;C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll;C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll;C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll;C:\Users\oded\AppData\Roaming\pyRevit-Master\bin\engines\CPY385\pyRevitLabs.PythonNet.dll;C:\Windows\Microsoft.Net\assembly\GAC_64\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll’, ‘PYREVIT_APPTELEMETRYHANDLER’: <PyRevitLabs.PyRevit.Runtime.EventTelemetry object at 0x000000000000060C [PyRevitLabs.PyRevit.Runtime.EventTelemetry]>, ‘PYREVIT_TELEMETRYSERVER’: ‘’, ‘PYREVIT_RIBBONUPDATOR’: None, ‘PYREVIT_HOOKSHANDLER’: <PyRevitLabs.PyRevit.Runtime.EventHooks object at 0x000000000000060D [PyRevitLabs.PyRevit.Runtime.EventHooks]>, ‘PYREVIT_CPYVERSION’: ‘385’, ‘PYREVIT_HOOKS’: Dictionarystr, Dictionary[str, str] , ‘PYREVIT_ROUTESROUTES’: {}, ‘PYREVIT_STYLESHEET’: ‘C:\Users\oded\AppData\Roaming\pyRevit-Master\pyrevitlib\pyrevit\output\outputstyles.css’, ‘PYREVIT_LOGGINGLEVEL’: 30, ‘PYREVIT_VERSION’: ‘4.8.13.23182+2215’, ‘PYREVIT_CLONE’: ‘master’, ‘PYREVIT_LOADEDASSMS’: ‘pyRevit_2024_051d618f79f8ac9a_pyRevitCore;pyRevit_2024_4cc16fc9f989dc11_pyRevitTools;pyRevit_2024_bda51b74caee0cb1_FormX’, ‘PYREVIT_TELEMETRYDIR’: ‘’, ‘PYREVIT_APPTELEMETRYSERVER’: ‘’, ‘PYREVIT_UUID’: ‘d74d3285-2ba6-454c-b8b1-3e131ee05474’, ‘PYREVIT_TABCOLORIZER’: <type ‘DocumentTabEventUtils’>, ‘PYREVIT_TELEMETRYUTCTIMESTAMPS’: True, ‘PYREVIT_APPVERSION’: ‘2024.2’, ‘PYREVIT_IPYVERSION’: ‘277’, ‘PYREVIT_APPTELEMETRYSTATE’: False, ‘PYREVIT_FILELOGGING’: False, ‘PYREVIT_TELEMETRYFILE’: ‘’, ‘PYREVIT_TELEMETRYSTATE’: False}
None
jpitts
(JP)
April 30, 2024, 9:15pm
4
Are you trying to read system environment variables? What exactly are you trying to do?
There are pyrevit environment variables in case you need to store values to use later.
The one at the top here is added by one of my smart toggles to track its status
def toggle_state():
new_state = not script.get_envvar(DISABLEDIALOG_ENV_VAR)
script.set_envvar(DISABLEDIALOG_ENV_VAR, new_state)
script.toggle_icon(new_state)
If you really need to be able to set outside of revit, might try writing to a text file instead of env variable
1 Like
Oded_F
(Oded Fuhrmann)
May 1, 2024, 5:57pm
5
Thank you for your answer.
Our use case: we have a supporting server running, but it’s host and port vary. Of course we can hard code it / set in an env file as a workaround yet… we would like to setenv these values from command line and use them from within pyrevit scripts. Is this possible?