使用Python win32com操作PowerDesigner时遇AttributeError: .Models问题求助
使用Python win32com操作PowerDesigner时遇AttributeError: .Models问题求助
我最近在尝试用Python的win32com模块自动生成PowerDesigner活跃工作区里多个物理模型的报表,刚接触Python不久,边学边做,但现在碰到了一个棘手的问题。
我用下面这段代码(已经借助GPT调整过格式),但在第15行触发了属性错误,看起来workspace对象并没有Models这个属性。我到处找相关的文档但都没找到,有没有人遇到过类似问题或者能给点思路?
错误信息:
AttributeError: .Models
import win32com.client import os from pathlib import Path # Connect to PowerDesigner pd = win32com.client.Dispatch("PowerDesigner.Application") # Get the active workspace workspace = pd.ActiveWorkspace # Get the Downloads folder path downloads_folder = str(Path.home() / "Downloads") # Iterate through open models in the workspace for model in workspace.Models: print(f"Processing model: {model.Name}") # Iterate through reports in the model for report in model.Reports: if "model report" in report.Name.lower(): # Generate a filename for the report filename = f"{model.Name}_{report.Name}.rtf" filepath = os.path.join(downloads_folder, filename) print(f"Saving report: {filename}") # Save the report try: report.Export(filepath, "RTF") print(f"Report saved to: {filepath}") except Exception as e: print(f"Error saving report: {e}") # Close the model print(f"Closing model: {model.Name}") model.Close() print("Process completed.")
备注:内容来源于stack exchange,提问作者Darren Daly
相关产品推荐
相关产品推荐

