Batch Import/ insert 3dm or gf file objects

I plan to import around 100 3dm objects. I have an csv file that contains all the names of the objects and the coordinates that I want to insert of the files. Is there a way to batch import? Thanks

Hi Yang,

It is certainly possible to read a comma-delimited file with either RhinoScript or Rhino.Python. And with the file read and the data parsed, you can then script the Insert or Import command, whichever is required.

So to answer your question, yes there is a way to batch import.

– Dale

Hi, Dale, thanks. But how can I do it? With which command? I tried to search insert or import in the rhinoPython documentary, it didn’t seem to have the corresponding function…

Hi Yang,

Here is a quick sample in RhinoScript. I’m sure you can do the same with Rhino.Python. This should get you started.

Sub TestYang

  ' Declare local variables
  Dim strName, arrData, row
  Dim strFile, arrPoint, arrObjects

  ' Have the user select a csv file
  strName = Rhino.OpenFileName("Open", "Comma Delimited (*.csv)|*.csv||")
  If IsNull(strName) Then Exit Sub

  ' Read the csv file
  arrData = Rhino.ReadDelimitedFile(strName)
  If IsNull(arrData) Then Exit Sub

  ' Verify the array has four columns
  If UBound(arrData, 2) <> 3 Then Exit Sub

  ' Process each row
  If IsArray(arrData) Then
    For row = 0 To UBound(arrData, 1)
      ' Get the filename and surround in double quote characters
      strFile = Chr(34) & arrData(row, 0) & Chr(34)
      ' Get the base point
      arrPoint = Array(arrData(row, 1), arrData(row, 2), arrData(row, 3))
      ' Script the Import command
      Call Rhino.Command("_-Import " & strFile & " _Enter")
      ' Get the imported objects
      arrObjects = Rhino.LastCreatedObjects
      ' If successful, move the objects to the base point
      If IsArray(arrObjects) Then
        Call Rhino.MoveObjects(arrObjects, Array(0, 0, 0), arrPoint)
      End If
  End If

  ' Unselect everything
  Call Rhino.UnselectAllObjects

End Sub (917 Bytes)

– Dale

Thank you very much Dale, right now I need to dig into the corresponding command in python, Call Rhino.Command("_-Import " & strFile & " _Enter"). Or actually I can just try to use Rhinoscript.

I’m not sure about the format. For example, the file I want to import is “A.3dm”. path:D:\10_PROJECTS\

I tried
import rhinoscriptsyntax as rs
rs.Command("-Import “&“D:\10PROJECTS\A.3dm”&” _Enter")

Always returns file not found.

I answered this in your other thread… --Mitch

Hi Yang,

In Python, the backslash “” path separator is also a python escape character. Double them, or better yet, use “r” raw python literals instead:


For example:

import rhinoscriptsyntax as rs
file = 'C:\\Users\\Dale\\Desktop\\A.3dm'
rs.Command('_-Import ' + file + ' _Enter')

– Dale


Thanks a lot Dale!