Error when run with alias

Hi,
I get the attached error when i run my script with an alias but not when i run it with the rhino script editor. Can someone tell me why?


1601-A.zip (814.0 KB)
covert_to_stp-2.py (1.4 KB)

1 Like

Could it be path related, when I put your code into ChatGPT it wants to make changes to bulletproof the path logic. Try this script:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import os
import Rhino
import Eto

def __BrowseForFolder():
    try:
        dlg = Eto.Forms.SelectFolderDialog()
        dlg.Directory = Rhino.ApplicationSettings.FileSettings.WorkingFolder
        if dlg.ShowDialog(None) == Eto.Forms.DialogResult.Ok:
            return dlg.Directory
    except Exception as e:
        print(f"Error browsing folder: {e}")
    return None

def convert_sldprt_to_stp(folder_path):
    if not folder_path:
        print("No folder selected.")
        return
    
    # Get all .SLDPRT files in the folder
    sldprt_files = [f for f in os.listdir(folder_path) if f.lower().endswith('.sldprt')]
    
    if not sldprt_files:
        print("No .SLDPRT files found.")
        return
    
    for sldprt_file in sldprt_files:
        try:
            # Construct full file paths
            sldprt_path = os.path.join(folder_path, sldprt_file)
            stp_path = os.path.join(folder_path, os.path.splitext(sldprt_file)[0] + '.stp')
            
            # Open the .SLDPRT file in Rhino
            if not rs.Command(f'_Open "{sldprt_path}" _Enter'):
                print(f"Failed to open {sldprt_path}")
                continue
            
            # Save the file as .STP
            if not rs.Command(f'_-SaveAs "{stp_path}" _Enter'):
                print(f"Failed to save {stp_path}")
                continue
            
            # Close the file
            sc.doc.Modified = False
            Rhino.RhinoApp.RunScript("_-New _None", False)
        except Exception as e:
            print(f"Error processing {sldprt_file}: {e}")

# Main execution
folder_path = __BrowseForFolder()
convert_sldprt_to_stp(folder_path)

With this you should at least see if there are path issues in the output

Your text string to rs.Command is probably not right, quotes in the wrong spot or something.

Actually I think the issue is that you need to tell the script what Python to use now in Rhino 8:

Try adding this to the top, and it will work from the alias:
#! python3

Worked for me:
image

I downloaded the newest build and installed it and it works now. Sorry for wasting your time. I will remember to check that first next time. Thanks for helping. I’m new to scripting.

That’s interesting because I have the latest build, and got your same error until I added the above text to the python script… but only when run as an alias…

Strange. I will add that just to be safe. Thanks again.

1 Like