Message 1 of 3
pyRevit: CPython (Python 3) equivalent of the IronPython (Python 2) "import clr"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good day.
I am using pyRevit. If I initiate my code with " #! python3 " then CPython (Python 3) will be used. If I do not then IronPython (Python 2) will be used.
In IronPython, the clr module points to the following:
SCRIPT:
import clr
print(dir(clr)
OUTPUT:
['AddReference', 'AddReferenceByName', 'AddReferenceByPartialName', 'AddReferenceToFile', 'AddReferenceToFileAndPath', 'AddReferenceToTypeLibrary', 'ArgChecker', 'ClearProfilerData', 'CompileModules', 'CompileSubclassTypes', 'Convert', 'Deserialize', 'Dir', 'DirClr', 'EnableProfiler', 'GetBytes', 'GetClrType', 'GetCurrentRuntime', 'GetDynamicType', 'GetProfilerData', 'GetPythonType', 'GetString', 'GetSubclassedTypes', 'ImportExtensions', 'IsNetStandard', 'LoadAssemblyByName', 'LoadAssemblyByPartialName', 'LoadAssemblyFromFile', 'LoadAssemblyFromFileWithPath', 'LoadTypeLibrary', 'Reference', 'References', 'ReferencesList', 'ReturnChecker', 'RuntimeArgChecker', 'RuntimeReturnChecker', 'Self', 'Serialize', 'SetCommandDispatcher', 'StrongBox', 'Use', '__name__', '__package__', 'accepts', 'returns']
When running this with CPython, it seems to point to a completely different module (I believe pythonnet).
SCRIPT:
#! python3
import clr
print(dir(clr)
OUTPUT:
-- too long to post here, but not the same as the first output.
My question is what is the equivalent module or method to obtain the CLR module that is used with IronPython (Python 2)?
clr.Reference[DB.IntersectionResultArray]() works in Python 2, but in Python 3 I get the error, " Unable to find assembly 'DB.IntersectionResultArray()'."
Thank you in advance.