Python Script to batch .dwg to .obj

I wonder if someone can help me out here. I am trying to make a batch conversion script with Python and I have no idea what I am doing. I found another script on the forum that I modified and it is almost doing what I need. The only thing missing is control of the mesh settings when exporting to .obj. The default setting are a bit course for my needs. This is the code I have thus far. Thanks in advance!

-Shane

import rhinoscriptsyntax as rs
import os.path
 
def BatchSaveAs():

    folder = "/Users/shane/Desktop/dwg-in"
    saveFolder = "/Users/shane/Desktop/obj-out"

    for filename in os.listdir(folder):
        if filename.endswith(".dwg"):
            fullpath = os.path.join(folder,filename).lower()
            rs.Command("-Import {} _Enter".format(fullpath))
            comm="_-ExportAll "
            rs.Command(comm + chr(34) + saveFolder + "/" + filename + ".obj" + chr(34)  + " _Enter" + " _Enter")
            rs.Command("Delete")
    
BatchSaveAs()

Hello - See if you can see the obj export options if you remove the second “Enter” in your command string.

-Pascal

Thank you Pascal, that does work but it requires me to manually enter the values for each file. Is there a way to enter export settings in the script? I have over a thousand of these files to batch.

Thanks,

-Shane

Bumping this again as I have not been able to figure it out myself. I have the script in my first post working well but my mesh setting need to be higher as I am getting very jagged renderings. I found another batch script written by Mitch Heynick that appears to be setting the mesh quality on export but I have not been able to add the functionality into my script. Below is the part of Mitch’s code that I believe is setting the export quality. Is there anyway I can add something like this into my script?

Thanks for the help.

def GetOBJSettings():
e_str = "_Geometry=_Mesh "
e_str+= "_EndOfLine=CRLF "
e_str+= "_ExportRhinoObjectNames=_ExportObjectsAsOBJGroups "
e_str+= "_ExportMeshTextureCoordinates=_Yes "
e_str+= "_ExportMeshVertexNormals=_Yes "
e_str+= "_CreateNGons=_No "
e_str+= "_ExportMaterialDefinitions=_No "
e_str+= "_YUp=_No "
e_str+= "_WrapLongLines=Yes "
e_str+= "_VertexWelding=_Unmodified "
e_str+= "_WritePrecision=16 "
e_str+= "_Enter _DetailedOptions "
e_str+= "_JaggedSeams=_No "
e_str+= "_PackTextures=_No "
e_str+= "_Refine=_Yes "
e_str+= "_SimplePlane=_No "
e_str+= "_AdvancedOptions "
e_str+= "_Angle=15 "
e_str+= "_AspectRatio=0 "
e_str+= "_Distance=0.01 "
e_str+= "_Grid=16 "
e_str+= "_MaxEdgeLength=0 "
e_str+= "_MinEdgeLength=0.0001 "
e_str+= "_Enter _Enter"
return e_str