首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python将ref int作为参数传递

Python将ref int作为参数传递
EN

Stack Overflow用户
提问于 2021-10-29 17:08:20
回答 1查看 96关注 0票数 0

通过win32com.client在我的python项目中使用tlb库。我很容易地处理了许多内置函数,但是其中一个主要函数获得了其中两个被标记为ref int的参数列表。当我试图将python整数传递给函数时,我会得到pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 5)错误,这显然是因为传递给对象的一些参数错误。

这是我的python代码:

代码语言:javascript
复制
import sldworksPython as solidWorks
import sldconstPython as solidConst
import win32com.client


swApp: solidWorks.ISldWorks = win32com.client.Dispatch(solidWorks.SldWorks.CLSID)
swConst = solidConst.constants

fileName = "Assem Of Hinge.SLDASM"
docType = int(swConst.swDocASSEMBLY)
config = int(swConst.swOpenDocOptions_AutoMissingConfig)
error = int(swConst.swFileNotFoundError)
warning = int(swConst.swFileLoadWarning_AlreadyOpen)

print(type(error))

swApp.OpenDoc6(
    fileName,    
    docType,
    config,
    error,
    warning
)

下面是openDoc6函数:

代码语言:javascript
复制
ModelDoc2 OpenDoc6(string FileName, int Type, int Options, string Configuration, ref int Errors, ref int Warnings);

这个错误把我吓坏了,我真的不想在这个项目中使用C#。谢谢你的帮忙

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-30 06:57:25

感谢@BoarGules,我刚刚下载了一个名为pySW的SW库。我想知道函数在那里是如何工作的,所以我刚刚检查了它们,并且理解了如何传递一个整数作为C#函数的引用。

我在下面补充我的解决办法:

代码语言:javascript
复制
import sldconstPython as solidConst
import win32com.client
import pythoncom
import pySW



swApp: solidWorks.ISldWorks = win32com.client.Dispatch(solidWorks.SldWorks.CLSID)
swConst = solidConst.constants

fileName = "Assem Of Hinge.SLDASM"
docType = swConst.swDocASSEMBLY
docOpts = swConst.swOpenDocOptions_AutoMissingConfig
error = win32com.client.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, swConst.swFileNotFoundError)
warning = win32com.client.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, swConst.swFileLoadWarning_AlreadyOpen)

swApp.OpenDoc6(fileName, docType, docOpts, "", error, warning)

这很奇怪,因为VScode没有建议我使用任何pythoncom常量。不管怎么说,希望这会对面对这样问题的人有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69772534

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档