我想使用结构分析(土木工程)程序Autodesk Robot Structural Analysis的API。 使用
IronPython
我按如下方式初始化变量:
import clr
clr.AddReferenceToFileAndPath(‘mypfad\Interop.RobotOM.dll’)
from RobotOM import *
robapp = RobotApplicationClass()
robproj = robapp.Project
robstruct = robproj.Structure
有了
robstruct
,我可以调用 API 函数并继续工作。
现在我想对
Python 3
做同样的事情。我尝试过使用 ctypes
和 numpy.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>
我不知道如何继续。
我的问题是:这是正确的方法吗?我该如何继续?
已编辑 05.10.2018
原始代码带有
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
根据
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
结果:
AttributeError: function 'RobotApplicationClass' not found
已于2018年10月16日编辑
第三次尝试:
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()
结果:
AttributeError: function 'RobotApplicationClass' not found
试试这个:
from ctypes import*
your_dll = cdll.LoadLibrary(‘mypfad\Interop.RobotOM.dll ')
如果成功加载,您就可以访问该 dll 文件中的所有类和函数。您可以使用
your_dll.nameofclass
调用主题。
我也在为同样的事情而苦苦挣扎。你找到解决办法了吗?
干杯! 比约恩