[Python] Python script to generate powerdesigner reports for all open models within a workspace

Discussão em 'Python' iniciado por Stack, Dezembro 7, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to automate the creation of powerdesigner data model reports on multiple physical models in an active workspace using Python- more using the specifically the win32com module. I'm fairly new to Python so trying to figure it out as I go but have hit a brick wall.

    I am using the below code (Refactored through GPT for formatting) but am getting an attribute error on line 15 so I'm guessing workspace doesn't have an attribute called Models. Have been looking everywhere for relevant documentation around this but haven't found it anywhere.

    Anyone come across this or have any ideas?

    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.")

    Continue reading...

Compartilhe esta Página