The task
Export layers as obj files from Rhino.
The issue
When using Python scripting, I run an export command. Instead of exporting the model, a dialog is presented in the interface. If I click the export interface, it works fine. However it brings up the dialog box for every layer. I have many many layers though and I would like to automate the entire export process.
The end goal is to display the obj files in webGL via three.js.
I am new to Python and Rhino, but know PHP and JavaScript, so I understand the concepts well enough and have watched a few tutorials on Python so I can begin working on this script.
What I have tried
I am using Rhino, Atom/Python.
import scriptcontext
import rhinoscriptsyntax as rs
from Rhino.Geometry import Point3d
def layerNames(sort=False):
rc = []
for layer in scriptcontext.doc.Layers:
if not layer.IsDeleted: rc.append(layer.FullPath)
if sort: rc.sort()
return rc
rs.EnableRedraw(False)
strPath = rs.DocumentPath()
strName = rs.DocumentName()
arrLayers = layerNames(False)
for layerName in arrLayers:
objs = scriptcontext.doc.Objects.FindByLayer(layerName)
rs.Command("_-Export "+layerName+".obj", False)
Notes
I was thinking of using python native file saving (open("layername.json", "a"). The thought is to somehow get the mesh from the objects in each layer, convert that to three.js json and use that instead. But I don't know how to get a mesh from a layer. I have imported Rhino.Geometry to see if it was helpful. I don't know how to find a mesh to convert, or if I can somehow use the native export command in an automated fashion and just use obj files.