Batch convert 2000 rhino files to 3ds and obj files respectively

Hi~I am puzzled by the problem to convert around 2000 rhino files to obj and 3ds files respectively
I try to use AHK window automatic script to simulate the human click operation,e.g click ‘import’, assign path, click ok, and then wait for a few seconds to totally import, and then click ‘export’, well this is a little fool and clumsy, especially low efficient

Is there any more efficient way to convert a huge amount of files?like 500 rhino files or even 2000 rhino files?The target format is 3ds and obj,I know to convert them in the same open file can be a disaster for CPU,this way i tried is inconvenient and anti-human-and-computer,if one step crash,all crash,and so do i

The core thought should be converting each of them one by one in queue aumatically by script .

Below is a simple example i want to show:

i think there must be some script to help me,BTW,i master python,so if you have any direction or good suggestion ,please tell me ,thanks !!!

I hacked the following script together from a couple of others I had. Will save all .3dm files found in a given folder as .obj. Check/modify the .obj export settings (meshing parameters, etc). as you need. If you say you master Python you can probably adapt this script to do .3ds.

–Mitch

BatchConvertToObj.py (2.4 KB)

1 Like

Thanks for your good help!! it help me a lot!!

Actually I`m trying to do a batch convert between 3ds to obj and add an name extension (e.g. “convert”).to the converted files. Can you give me hint maybe how to solve that? I am always getting this strange “Text (Unweld=No”) in the beginning.

Hi @user333,

Can you provide any sample code that isn’t working for you?

– Dale

import rhinoscriptsyntax as rs
import scriptcontext as sc
import os

"""Converts all 3ds files in a  folder to .3ds. Original 3dm files are preserved.
Modify the .obj export settings as needed.  Can be adapted to other export formats.
Script by Mitch Heynick 10.08.19! 
use this in Rhino command line to find export settings: 
-SaveAs "C:\Users\aurelius\Desktop\furniture selected\Vitra_ID_Mesh\transform\transform.obj" """


def 3DSSettings():
    e_str= "_Unweld=_No "
    e_str+= "_WeldAngle=22.5 "
    e_str+= "_OpenImportMeshesAsSubdSurfaces=No "
    e_str+= "_ImportLights=_No "
    e_str+= "_ImportCameras=_No "
    e_str+= "_PromptToScaleOnImport=_No "
    e_str+= "_Enter _Enter"
    return e_str

def Get3DSSettings():
    e_str= "_SaveViews=No "
    e_str+= "_SaveLights=No "
    #e_str+= "_Enter _DetailedOptions "
    e_str+= "_PolygonDensity=50 " 
    #---detailed options---
    e_str+= "_JaggedSeams=_No "
    e_str+= "_PackTextures=_No "
    e_str+= "_Refine=_Yes "
    e_str+= "_SimplePlane=_No "
    e_str+= "_AdvancedOptions "
    e_str+= "_Angle=0.0 "
    e_str+= "_AspectRatio=6.0 "
    e_str+= "_Distance=0.0 "
    e_str+= "_Grid=0 "
    e_str+= "_MaxEdgeLength=0 "
    e_str+= "_MinEdgeLength=0.0001 "
    e_str+= "_Enter _Enter"
    return e_str

def BatchConvertTo3DS():
    #Get folders
    folder = rs.BrowseForFolder(message="Select folder to process")
    if not folder: return
    
    import_sett=3DSImportSettings()
    export_sett=Get3DSExportSettings()
    
    found = False ; counter=0 ; ext="3ds"
    rs.EnableRedraw(False)
    
    #Find 3ds files in the folder
    for filename in os.listdir(folder):
        if filename.endswith(".3ds"):
            found = True ; counter+=1
            fullpath=os.path.join(folder,filename).lower()
            #allow the current file to close without the save dialog
            rs.DocumentModified(False)
            rs.EnableRedraw(False)
            #Open file to convert
            comm_str="_-Import "+chr(34)+fullpath+chr(34)+import_sett+" _Enter"
            rs.Command (comm_str, False)
            e_file_name = "{}.{}".format(fullpath[:-4],ext)	
            #save the file using the file name/path and settings
            rs.Command('-_SaveAs "{}" {}'.format(e_file_name,export_sett),False)
    if not found:
        msg="No 3ds files found in selected folder!"
    else:
        msg="{} files converted to .3ds format".format(counter)
    
    #open a blank document to finish
    rs.DocumentModified(False)
    rs.Command("_-New _None",False)
    rs.Command("SetRedrawOn",False)
    rs.MessageBox(msg)
        
BatchConvertTo3DS()

Is there a script to convert the other way? .obj to .3dm? I’m not finding any expamples of this.

No. That’s “Reverse Engineering,” the worst task in all of 3D.

You can try the following script:

BatchConvertOBJTo3dm.py (2.0 KB)

Note, you may want to modify the default import settings by opening the script in a text editor and changing any of the following to the options you want:

Also you can change the blank template file it opens with at the end by changing the last line:

Note that the .3dm files will just contain the mesh objects that were in the .obj files, it does not convert the meshes to NURBS surfaces.

Helvetosaur, thank you very much! Yes mesh objects is fine for my purposess now. I mostly want to have a folder of assets show up in the rhino file explorer. This script has me nearly to where I want to be. I wonder if there is a way to change the display mode useing rhino script. When i open each file and set the active viewport to top and rendered mode and then save the file the thoumbnail in the file explorer looks the way I want it to. I’ve tried to modify your script by adding these lines within the for in loop:

 rs.CurrentView('Top')
 rs.ViewDisplayMode("Top", "Rendered")

This sets the viewport to top in the file thumbnail but not to rendered. I wonder if i’ve made a mistake (as i really don’t know what i’m doing) or if this is posible.

thanks agian for your help!

I attached the modified version of the script below

BatchConvertOBJTo3dm_modified.py (2.0 KB)

OK, here’s a variant to try. Note the problem is twofold, you have to make sure the current (Top) view is maximized and has rendered mode activated. However, this appears to require a screen redraw to make it work.

If you comment out the rs.Redraw() on line 50, you get wireframe thumbnails. Doing the redraws to get a rendered thumbnail will slow the process down and you are going to see lots of screen flashing as it does the conversions. But it appears to work. Maybe someone has a better workaround.

BatchConvertOBJTo3dm-Special.py (2.3 KB)

1 Like

Thats exactly what i need. Thank you very much!