简体   繁体   中英

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. The last line in the following does not work and I get an 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. However, with .NET we have to convert the enum to an int (ie. (int)swDocumentType.swDocPART ). In the case of swDocPART, the enum value is 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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