Python create 3dm file and save/export objects in them

hello there, I want to make some kind of a database, but with rhino files. So,for example, in the current Rhino file I create 2 objects. When this custom command is executed, it should select the 2 objects, loop thru them, and then save them, or export them, INDIVIDUALY in a .3dm file, at the path that I want. Eventually, I’m thinking to save the .3dm file with the object GUID for a better control. I have all the puzzle’s parts in my mind, but only the export part is unknown.

So, in conclusion, I need the python command which exports objects, and the way to create the empty 3dm file

found the solution
check link https://stackoverflow.com/questions/29401951/export-layers-as-obj-from-rhino3d

2 Likes

Hi @cotoc_george,

You can also take a look at my code here for a rather fast Python OBJ export:

It’s meant for Grasshopper to export sequences of OBJs for animation purposes - basically like you would export rendered frames for a video -, but it should also work for single OBJ export in Rhino. It probably only needs some minor modifications.

in the end, the code looks like this:.

import rhinoscriptsyntax as rs
import os
def dbmaker():
strPath = rs.DocumentPath()
objects=rs.GetObjects()
if objects:
for object in objects:
objGuid=str(rs.coerceguid(object))
objExtension=’.3dm’
expCommand=’-_Export “{}{}”’.format(os.path.join(strPath,objGuid),objExtension)
rs.EnableRedraw(False)
print (‘expcommand’,expCommand)
rs.UnselectAllObjects()
rs.SelectObjects(object)
rs.Command(expCommand+’ _Enter’)

dbmaker()