pyRevit: CPython (Python 3) equivalent of the IronPython (Python 2) "import clr"

pyRevit: CPython (Python 3) equivalent of the IronPython (Python 2) "import clr"

bdschust18
Participant Participant
2,229 Views
2 Replies
Message 1 of 3

pyRevit: CPython (Python 3) equivalent of the IronPython (Python 2) "import clr"

bdschust18
Participant
Participant

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.  

 

 

0 Likes
2,230 Views
2 Replies
Replies (2)
Message 2 of 3

bhprest
Advocate
Advocate

Long story short is that cpython doesn't have a built in way to interface with the clr (to my knowledge anyway). Take a look at pythonnet.

0 Likes
Message 3 of 3

SONA-ARCHITECTURE
Advocate
Advocate

https://forums.autodesk.com/t5/revit-api-forum/find-intersection-point-between-curves-using-cpython3...

Pierre NAVARRA
SONA-Architecture.
http://www.sona-architecture.com
https://fr.linkedin.com/in/pierre-navarra-62032a107
0 Likes