Site Tools


Batch Render

Developer: RhinoScript
Summary: Demonstrates how to recurse through a folder and render every Rhino file.

Question

I have several files that I would like to render. Is there a script that helps automate this? Or, do I just have to open each model one at a time.

Answer

The following RhinoScript will recurse through a selected folder, open each Rhino model, and perform a render operation.

 Option Explicit
 
 ' Run the subroutine
 Call BatchRender
 
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ' BatchRender
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 Sub BatchRender()
 
   ' Allow the user to interactively pick a folder
   Dim sFolder
   sFolder = Rhino.BrowseForFolder(, "Select folder to process", "Batch Render" )
   If VarType( sFolder ) <> vbString Then Exit Sub
 
   ' Create a file system object
   Dim oFSO
   Set oFSO = CreateObject( "Scripting.FileSystemObject" ) 
 
   ' Get a folder object based on the selected folder
   Dim oFolder
   Set oFolder = oFSO.GetFolder( sFolder )
 
   ' Process the folder
   RecurseFolder oFolder
 
   ' Open an empty model
   Rhino.Command "_-New _None", 0
 
   ' Release the objects
   Set oFolder = Nothing
   Set oFSO = Nothing
 
 End Sub
 
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ' RecurseFolder
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 Sub RecurseFolder( oFolder )
 
   ' Process each file in the folder
   Dim oFile
   For Each oFile In oFolder.Files
     ProcessFile oFile.Path
   Next
 
   ' Remark out the following lines if you do not want
   ' to recursively process the folder

   ' Process each subfolder in this folder
   Dim oSubFolder
   For Each oSubFolder In oFolder.SubFolders
     RecurseFolder( oSubFolder )
   Next
 
 End Sub 
 
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ' ProcessFile
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 Sub ProcessFile( sFile )
 
   ' Once we have gotten here, we have a valid file name.
   ' In this case, we are interested in just 3DM files.

   Dim sBitmap
   If (InStr(LCase(sFile), ".3dm") > 0) Then
     sBitmap = Replace(sFile, ".3dm", ".jpg", 1, -1, 1)
     Rhino.DocumentModified False
     Rhino.Command "_-Open " & Chr(34) & sFile & Chr(34), 0
     Rhino.Command "_-Render", 0
     Rhino.Command "_-SaveRenderWindowAs " & Chr(34) & sBitmap & Chr(34), 0
     Rhino.Command "_-CloseRenderWindow", 0
     Rhino.DocumentModified False
   End If  
 
 End Sub


developer/scriptsamples/batchrender.txt ยท Last modified: 2015/10/14 by sandy