VBScript - import and move to layer

hi,
i’m not sure to understand the post before, in fact i don’t understand all the post…
my problem, is that i want to import a file in my rhino file, but i want to put all the file in a layer. and this layer must take the name of the file just imported…
all that with vb script, because sometime, i’ve got a lot of files to import in one…
thank you for your help.

Moved to a new topic.

@onlyforpeace, please post your script. If you import and know the filename, the imported objects should still be selected after importing (if there are no locked or hidden objects in your rhino file). You should then be able to create a new layer based on the filename and change the selected objects to this new layer.

Here is an example with a single file:

Option Explicit

Call Main()
Sub Main()
    Dim strFilePathName, strCmd, fso, strFileName, strLayer
    	
    ' ask for a file 
    strFilePathName = Rhino.OpenFileName("Import", "Rhino files(*.3dm)|*.3dm||")
    If IsNull(strFilePathName) Then Exit Sub
    	
    ' import it
    strCmd = "_-Import " & chr(34) & strFilePathName & chr(34) & " _Enter"
    Rhino.Command strCmd, True
    	
    ' get the file name without extension
    Set fso = CreateObject("Scripting.FileSystemObject") 
    strFileName = fso.GetBaseName(strFilePathName)
    		
    ' create a new layer
    strLayer = Rhino.AddLayer(strFileName)
    	
    ' put imported objects on this layer
    Call Rhino.ObjectLayer(Rhino.SelectedObjects(), strLayer)

End Sub

_
c.

1 Like

Ok… thank you so much!! i didn’t find the openfilename command.
what can i say… i would like to found it myself, but thank you to the rhino community and you of course!!

Ok, now i search to batch all file in a repertory…
for each file, one layer…
can i use openfilenameS command,
and for each file i launch your script…??

I tried and it’s ok!

Option Explicit
'Script written by Clement de la communauté rhino
'VBSCRIPT- import multiple and move to layer - FORUM -
'Script version mardi 3 septembre 2019 09:41:03

Call Main()
Sub Main()
Dim arrFilePathName, strFilePathName,strCmd, fso, strFileName, strLayer

’ ask for a file
arrFilePathName = Rhino.OpenFileNames(“Import”)
If IsNull(strFilePathName) Then Exit Sub

For Each strFilePathName In arrFilePathName
’ import it
strCmd = “_-Import " & chr(34) & strFilePathName & chr(34) & " _Enter”
Rhino.Command strCmd, True

’ get the file name without extension
Set fso = CreateObject(“Scripting.FileSystemObject”)
strFileName = fso.GetBaseName(strFilePathName)

’ create a new layer
strLayer = Rhino.AddLayer(strFileName)

’ put imported objects on this layer
Call Rhino.ObjectLayer(Rhino.SelectedObjects(), strLayer)
rhino.unselectallobjects
Next

End Sub

2 Likes