簡體   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