[Python] How to check out a file using SOLIDWORKS PDM API in Python?

Discussão em 'Python' iniciado por Stack, Julho 15, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to work with the SOLIDWORKS PDM Professional API from Python.

    I know the PDM API is COM-based and usually used from C# or VB.NET, but I prefer Python for automation scripts.

    In the Vault User Interface, I can see user information (who is logged in, who has a file checked out, etc.), and I can check out files without any problem.

    However, when I use Python, I feel very limited. For example:

    I cannot successfully check out (lock) files from Python.

    I cannot easily retrieve which user I'm logged in as.

    import clr

    clr.AddReference(r"C:\Program Files\SOLIDWORKS PDM\EPDM.Interop.epdm.dll")

    from EPDM.Interop.epdm import EdmVault5

    vault = EdmVault5()
    vault.LoginAuto("CR Vault", 0)
    if vault.IsLoggedIn:
    print("Connected to vault!")
    else:
    print("Failed to connect.")

    vault_folder_path = r"C:\CR Vault"
    vault_file_path = r"C:\CR Vault\path_to_excel_spreadsheet"

    folder = vault.GetFolderFromPath(vault_folder_path)
    file = vault.GetFileFromPath(vault_file_path, folder)[0]

    print("Is locked:", file.IsLocked) # Locked == Checked out
    print("Locked by:", file.LockedByUser)
    print("Locked by (ID):", file.LockedByUserID)
    print("Current version:", file.CurrentVersion)

    # Try to check out
    file.LockFile(folder.ID, 0, 0)

    if file.IsLocked:
    print("File checked out successfully")
    else:
    print("Failed to check out file")

    # Get local copy as a workaround top copy a file
    version = 0
    flags = 0
    file.GetFileCopy(0, version, folder.ID, flags, "")
    local_path = file.GetLocalPath(folder.ID)
    print("Local path:", local_path)


    The error message when I try to checkout the file :

    COMException: (0x80040203): You don't have permission to perform this action.
    at EPDM.Interop.epdm.IEdmFile5.LockFile(Int32 lParentFolderID, Int32 lParentWnd, Int32 lEdmLockFlags)


    My questions

    1️⃣ Why can't I successfully check out files from Python, even though it works fine in the Vault UI?

    2️⃣ Why do I not have access to the same user info (like current user name) when using Python?

    3️⃣ Has anyone successfully performed advanced PDM automation purely in Python, including file checkout access datacard etc ?

    4️⃣ Are there recommended workarounds or patterns to achieve this in Python?

    What I can do so far

    • Log in to the vault
    • Get folders and files
    • Get some properties like IsLocked, LockedByUser, etc.
    • Copy local files using GetFileCopy() and get their local path with GetLocalPath()
    • Checking a file

    But I cannot check out files or get user details as I can in the UI.

    Continue reading...

Compartilhe esta Página