简体   繁体   English

使用 python 和 solidworks api 打开 solidworks 零件

[英]Opening solidworks part using python and solidworks api

I am trying to open a solidworks file using python and the solidworks api. I dont seem to understand the solidworks OpenDoc6 documentation.我正在尝试使用 python 和 solidworks api 打开一个 solidworks 文件。我似乎不了解 solidworks OpenDoc6 文档。 The last line in the following does not work and I get an AttributeError: swDocPART下面的最后一行不起作用,我得到一个 AttributeError: swDocPART

Does anyone happen to know what is wrong with my code?有没有人碰巧知道我的代码有什么问题?

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)

I am not familiar enough with Python and how it leverages the SolidWorks API libraries, specifically Enums.我不太熟悉 Python 以及它如何利用 SolidWorks API 库,特别是枚举。 However, with .NET we have to convert the enum to an int (ie. (int)swDocumentType.swDocPART ).但是,对于 .NET,我们必须将枚举转换为 int(即(int)swDocumentType.swDocPART )。 In the case of swDocPART, the enum value is 1.对于 swDocPART,枚举值为 1。

The document type enums can be found here - https://help.solidworks.com/2019/english/api/swconst/SOLIDWORKS.Interop.swconst~SOLIDWORKS.Interop.swconst.swDocumentTypes_e.html可以在此处找到文档类型枚举 - 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