简体   繁体   English

Python 3:使用ctypes或numpy.ctypeslib导入dll

[英]Python 3: import dll with ctypes or numpy.ctypeslib

I want to work with the APIs of the program of structural analysis (civil engineering) Autodesk Robot Structural Analysis . 我想使用结构分析(土木工程)程序Autodesk Robot Structural Analysis的API。 With IronPython I initialize the variables as follows: 使用IronPython我按如下所示初始化变量:

import clr
clr.AddReferenceToFileAndPath(‘mypfad\Interop.RobotOM.dll’)
from RobotOM import *
robapp = RobotApplicationClass()
robproj = robapp.Project
robstruct = robproj.Structure

With robstruct I can call the API functions and continue working. 使用robstruct我可以调用API函数并继续工作。

Now I'd like to do the same with Python 3 . 现在,我想对Python 3做同样的事情。 I have tried with ctypes and with numpy.ctypeslib without success: 我已经尝试使用ctypesnumpy.ctypeslib失败了:

import ctypes
lib_ctypes = ctypes.cdll[‘mypfad\Interop.RobotOM.dll']
print(lib_ctypes)
<CDLL 'mypfad \Interop.RobotOM.dll', handle 1a1ff900000 at 0x1a1e8e22710>

import numpy
lib_numpy = numpy.ctypeslib.load_library('Interop.RobotOM.dll', 'mypfad’)
print(lib_ numpy)
<CDLL 'mypfad\Interop.RobotOM.dll', handle 1a1ffb40000 at 0x1a1ffb194e0>

And I don't how to continue. 而且我不继续。

My questions are: is this the right way and how shall I continue? 我的问题是:这是正确的方法,我将如何继续?

Edited 05.10.2018 编辑05.10.2018

Original code with IronPython : IronPython原始代码:

import clr

# Add Robot Structural Analysis API reference
clr.AddReferenceToFileAndPath(
    'C:\Program Files\Common Files\Autodesk Shared\Extensions 2018\Framework\Interop\Interop.RobotOM.dll'
)

# Add needed import to be able to use Robot Structural Analysis objects
from RobotOM import *

# Connect to the running instance of Robot Structural Analysis
robapp = RobotApplicationClass()

# Get a reference of the current project
robproj = robapp.Project

# Get a reference of the current model
robstruct = robproj.Structure

An attempt according to the comment of The Machine : 根据The Machine的评论尝试:

import ctypes

my_dll = ctypes.cdll.LoadLibrary(
    'C:\Program Files\Common Files\Autodesk Shared\Extensions 2018\Framework\Interop\Interop.RobotOM.dll'
)

robapp = my_dll.RobotApplicationClass()
robproj = robapp.Project
robstruct = robproj.Structure

Result: 结果:

AttributeError: function 'RobotApplicationClass' not found

Edited 16.10.2018 编辑16.10.2018

Third attempt: 第三次尝试:

from ctypes import cdll
my_dll = cdll.LoadLibrary(
    'C:\Program Files\Common Files\Autodesk Shared\Extensions 2019\Framework\Interop\Interop.RobotOM.dll'
)
my_dll.RobotApplicationClass()

Result: 结果:

AttributeError: function 'RobotApplicationClass' not found

Try this: 尝试这个:

from ctypes import*
your_dll = cdll.LoadLibrary(‘mypfad\Interop.RobotOM.dll ')

If it is succesfully loaded than you can aces to all of classes and function in that dll file . 如果成功加载,则可以ace到该dll文件中的所有类和函数。 You can call theme with your_dll.nameofclass . 您可以使用your_dll.nameofclass调用主题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM