-
Environment
DetailsHi everyone, I hope you can help me with the following problem. I have already found diverese posts here and on other sites, but unfortunately couldn't solve the problem. The goal is to read a DLL, which is normally used in C#, into Python. There is a large list of methods, which is greatly simplified by the autocompletion. Unfortunately, I lose a strong convenience in the Python editor, that the interpreter in the static code can't execute the autocompletion (my guess). Thus, I cannot see in the editor what commands are available to me. BUT: If I execute the same commands directly in the console, the autocompletion works perfectly. Also all methods are loaded, which are in the modules. I have already tried this with different IDEs: PyCharm, VS2019/22, VSC, Eclipse. I have also had unsuccessful attempts with IronPython. Is there any way that this DLL gets pre-read in the editor or that the contents are known. I have read in some forum posts that so-called stubs should help... Unfortunately, however, I failed in the implementation. The DLL is obtained directly from the project website: https://www.nuget.org/packages/Aml.Engine [Download -> AMLEngine 2.1 v.1.7 - In this are also different .NET versions, which I have tested]. The DLLs are in the code directory and also added it to the system environment variables for testing. I also thought that replacing Import * with the names e.g. CAEXDocument would help.... sadly not. import clr
clr.AddReference("DLLs/AML.Engine")
import Aml.Engine
import Aml.Engine.CAEX
from Aml.Engine.CAEX import AttributeFamilyType
from Aml.Engine.CAEX import CAEXDocument
# from Aml.Engine.CAEX import *
# from Aml.Engine.CAEX.Extensions import *
def main():
doc = CAEXDocument.New_CAEXDocument()
ih = doc.CAEXFile.InstanceHierarchy.Append("IH1")
# etc. here goes the source code
if __name__ == '__main__':
main() The autocomplete should actually suggest NEW_CAEXDocument to me after doc=CAEXDocument. or other methods which follow. Unfortunately I don't get any of them. The same also by ih=doc.--- I get error messages like:
However, the script can be executed without problems. Many suggestions in forum posts were (so I feel) a bit far from the topic or my knowledge is not sufficient for this, since Python is quite new to me. I would be very grateful for any possible solutions. If there are any uncertainties or questions, I will answer them as fast as possible. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
I have the same problem, unfortunately found no solution. Have you? |
Beta Was this translation helpful? Give feedback.
-
In order to get autocomplete, you'll likely need to generate stubs for the c# dlls. Afaik, there's 2 projects that can do this: https://github.com/gtalarico/ironpython-stub You can then use the stubs as indicated in your IDE |
Beta Was this translation helpful? Give feedback.
The pyi files should not go in your source code. Python doesn't need to know about the pyi files, they are only there for the use to use.
If you follow the instructions here:
https://www.jetbrains.com/help/pycharm/stubs.html#install-stub
The stubs should not change anything about the runtime behaviour of the software.