繁体   English   中英

使用 python 和 solidworks api 打开 solidworks 零件

[英]Opening solidworks part using python and solidworks api

我正在尝试使用 python 和 solidworks api 打开一个 solidworks 文件。我似乎不了解 solidworks OpenDoc6 文档。 下面的最后一行不起作用,我得到一个 AttributeError: swDocPART

有没有人碰巧知道我的代码有什么问题?

import win32com.client

# part path and name
filePath = r'\Part1.SLDPRT'

# Connect to SolidWorks and open the document
swApp = win32com.client.Dispatch('SldWorks.Application')

if swApp is None:
    print("Error: Could not connect to SolidWorks")
else:
    print("Success: Connected to SolidWorks")

# Open the SolidWorks document using OpenDoc6
swDoc = swApp.OpenDoc6(filePath, win32com.client.constants.swDocPART, 0, "", 0, 0)

我不太熟悉 Python 以及它如何利用 SolidWorks API 库,特别是枚举。 但是,对于 .NET,我们必须将枚举转换为 int(即(int)swDocumentType.swDocPART )。 对于 swDocPART,枚举值为 1。

可以在此处找到文档类型枚举 - https://help.solidworks.com/2019/english/api/swconst/SOLIDWORKS.Interop.swconst~SOLIDWORKS.Interop.swconst.swDocumentTypes_e.html

暂无
暂无

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

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