Need advice on how to fix error

Import the necessary SOLIDWORKS PDM API libraries

import Dispatch
import time
import subprocess
import os

Create a SOLIDWORKS PDM API application object

sw_pdm_app = Dispatch(“SldWorksPDM.Application”)

Log in to the PDM vault

vault = sw_pdm_app.GetVault(“3D Printing Automation”)
vault.Login(“Admin”, “123456”)

Define the root folder in PDM where you want to start the search

root_folder = vault.GetFolderFromPath(r"$/Users\ADMIN\Desktop\3D Printing Automation")

Replace with the path to your Ultimaker Cura executable

cura_executable_path = “C:\Program Files\Ultimaker Cura 5.4.0\UltiMaker-Cura.exe”

Specify the Cura profile name you want to use

cura_profile_name = “Default”

Function to search for STL files and generate G-code with the specified profile

def search_and_generate_gcode(folder):
for file in folder.GetFiles():
if file.Type == Dispatch.PDMFILESType.PDMFILE_3D:
if file.Extension.lower() == “.stl”:
stl_file_path = file.GetLocalCopy()
print(f"Processing {stl_file_path}…“)
gcode_output_path = os.path.splitext(stl_file_path)[0] + “.gcode”
# Use Ultimaker Cura to generate G-code with the specified profile
subprocess.run([cura_executable_path, stl_file_path, “-p”, cura_profile_name, “-o”, gcode_output_path], check=True)
print(f"G-code generated for {stl_file_path} with profile ‘{cura_profile_name}’.”)

for subfolder in folder.GetFolders():
    search_and_generate_gcode(subfolder)

Loop with a 10-second refresh rate

while True:
search_and_generate_gcode(root_folder)
time.sleep(10) # Sleep for 10 seconds before the next search

The script will not log out of PDM here, allowing the user to continue using the vault.

the Error prompt: ModuleNotFoundError: No module named ‘Dispatch’

In order to preserve formatting, please select any code or traceback that you post and then click the </> button.

Dispatch is not a module, it’s a Windows function.

You need to install pywin32 and then use:

from win32com.client import Dispatch

in your Python script.

I see thanks for the insight. i will do the changes and try again.

I made the modifications, however there is a new error.

Please don’t post screenshots.

Copy and paste any code or traceback, and in order to preserve formatting, select the code or traceback that you posted and then click the </> button.

It’s complaining that it doesn’t recognise the name “SldWorksPDM.Application”. Are you sure that the name is correct?

1 Like

I apologize for the screenshot; I’m new to this and Python programming. may know what the correct name should be.

Why did you use the name “SldWorksPDM.Application”? Is that what it says in the documentation, with that exact spelling?

I asked Google about it and was given that answer.