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 rhinoscript.userinterface
#import rhinoscript.geometry
import Rhino
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")
print filenames
# 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
return 0
if( __name__ == '__main__' ):
RunCommand(True)
@bjornsyse, i can repeat that bug in Rhino 6. Meanwhile you could try this as a replacement:
import Rhino
import System
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:
return fd.FileNames
return []
def RunCommand():
title = "Open"
filtr = "STL Files (*.stl)|*.stl|All Files (*.*)|*.*||"
rc = OpenFileNames(title, filtr)
if not rc: return
print rc
RunCommand()
@Alain, it seems that the rs.OpenFileNames method has two buglets in Rhino 6.
It still uses ShowDialog() instead of ShowOpenDialog() and 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…