我的python代码使用pywin32,每次都运行失败

问题描述 投票:0回答:0

我正在尝试为 autodesk inventor 创建一个 api,我正在编写的代码总是缺少一些模块,即使它们在那里。 pywin32 不能与我正在使用的 python3.10 一起使用吗?这是我最新代码的副本:

import win32com.client

def open_inventor_file(file_path):
    try:
        # Get the active instance of the Inventor application
        inventorApp = win32com.client.Dispatch("Inventor.Application")

        # Make the application visible
        inventorApp.Visible = True

        # Get the Documents collection
        documents = inventorApp.Documents

        # Open the specified file
        doc = documents.Open(file_path)

        # Start a sketch on the first work plane
        part = doc.ComponentDefinition
        work_plane = part.WorkPlanes[1]
        sketch = part.Sketches.Add(work_plane)
        sketch.Edit()

    except Exception as e:
        print("Error opening Autodesk Inventor file:", str(e))

# Specify the file path of the Inventor file you want to open
file_path = r"N:\MISC\Part37.ipt"

# Call the function to open the specified file in Inventor
open_inventor_file(file_path)

帮助创建 api 或使用 pywin32

python api pywin32
© www.soinside.com 2019 - 2024. All rights reserved.