Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Because the Execute() command only returns result codes, there is no way to return data back to a max variable, but I discovered that if the python code stores data into an environment variable, that Maxscript can then read that variable in.
Python:
import os
os.environ['pythoncache'] = myData
Maxscript:
returnData = systemTools.getEnvVariable 'pythoncache'
This is WAY faster than dumping data to the filesystem.
Example:
sysVar = "PYTHON_RESULT"
myName = "Ray"
pythonCode = stringstream ""
format "import os\n" to:pythonCode
format "def hello_max(username):\n" to:pythonCode
format " message = f\"Hello {username}\"\n" to:pythonCode
format " os.environ['%'] = message\n" sysVar to:pythonCode
format "hello_max(\"%\")\n" myName to:pythonCode
python.execute pythonCode
result = systemTools.getEnvVariable sysVar
Output:
"Hello Ray"
I hope this helps someone.
Solved! Go to Solution.