I’m trying to import multiple STEP files using Python for rhino and started out slowly with this script trying to input file names. However, I get nothing in return from
rs.OpenFileNames. Nor can I select multiple files in that dialog-box. I’m on Windows 10 64 bit using Rhino 6.1
Am I doing something weird?
import rhinoscriptsyntax as rs
import scriptcontext as sc
__commandname__ = "ImportSTEPs"
# RunCommand is the called when the user enters the command name in Rhino.
# The command name is defined by the filname minus "_cmd.py"
def RunCommand( is_interactive ):
# Ask for STEP file input
filenames = rs.OpenFileNames("Open")
# you can optionally return a value from this function
# to signify command result. Return values that make
# sense are
# 0 == success
# 1 == cancel
# If this function does not return a value, success is assumed
if( __name__ == '__main__' ):
This is my output:
@bjornsyse, i can repeat that bug in Rhino 6. Meanwhile you could try this as a replacement:
def OpenFileNames(title=None, filter=None, folder=None, filename=None, extension=None):
fd = System.Windows.Forms.OpenFileDialog()
if title: fd.Title = title
if filter: fd.Filter = filter
if folder: fd.InitialDirectory = folder
if filename: fd.FileName = filename
if extension: fd.DefaultExt = extension
fd.Multiselect = True
fd.RestoreDirectory = True
if fd.ShowDialog() == System.Windows.Forms.DialogResult.OK:
title = "Open"
filtr = "STL Files (*.stl)|*.stl|All Files (*.*)|*.*||"
rc = OpenFileNames(title, filtr)
if not rc: return
@Alain, it seems that the
rs.OpenFileNames method has two buglets in Rhino 6.
It still uses
ShowDialog() instead of
fd.MultiSelect seems to be hardcoded (set to True) and not working. I can only select a single file. The method always returns
fd.FileNames which is empty, but
fd.FileName works when a single file was selected…
Thanks for reporting @clement, and thanks for the work around!