Script for batch converting 3DM to DXF or exporting to DXF from layers?

I’m using the nest feature of RhinoCam, it let’s me export 60 sheets of nested parts to files but only to .3DM which will mean nothing to the laser cutter operator. I contacted MecSoft and they suggested contacting McNeel, thought I’d try here first.

"You can check with McNeel support to see if they could come up with some sort of a script that can take the 3dm files and convert it to dxf’s without having to convert each file manually.

Alternatively you can check if they can help you with a script that can export each layer of the committed nest to a separate Dxf from Rhino. This might be more doable I think."

Hello - see how this script works for you - to run it save and then drag and drop onto Rhino, this will add an alias that will run the script much like a command"


You’ll want to do one export manually, so to speak, to set up the dxf options, then this script should just use the same. I just added dxf, but did not test much yet… =)

ExportLayers.rvb (1.5 KB)


I use Grasshopper to export and control layers. A relatively simply script, if you’re interested in going that route post an example file.

Here’s my export DXF by layer script. (1.7 KB)
Note that before you run the script, do one “dummy” export manually to set the ACAD export scheme, as the script will use the most recently used scheme.

1 Like

Hi all!, I know that I almost have the solution but I am stuck :frowning:

I need to export a single DXF file with all the selected curves (not a single file for each curve or each layer).

I think that is more simple that your .py codes but I can not find the solution. Maybe my problem is using the for when I want directly all the curves but rs.SelectObjects(sel_obj) causes error.

Any help?

Thank you so much

Select your curves, File- ‘export selected’, choose your file format, eg, dwg, dxf, etc etc

Hi I need it as a Python Script, exactly like the example but exporting all curves in one DXF file (my need is a little more complicated but with this help I think I will able to solve it)

To get all curve objects use crv_ids=rs.ObjectsByType(4) - check out the rs Help for the options with this method.

Here is a simple scripted DXF exporter (not specifically for curves): (1.2 KB)

1 Like

That’s it! Thank you so much, I really apreciate it :smiley:.

In fact, maybe I was focus and tired and I didn’t see the mistake but your functional solution is almost the same that the test I did (I think), seems that rhino python debugger is a little poor for that…

Another question…
Is it possible to compare the current documentPath with Rhino.Options.DefaultFileDialogDirectories.ExportDirectory?

I mean, if documentPath is not equal to Rhino.Options.DefaultFileDialogDirectories.ExportDirectory (parent path, it could be interesting to detect\ in order to extract a subpath to compare) then use documentPath to export files, else use the last used, stored in defailtFileDialogDirectories…

I am not sure what you are referring to here…

In Rhino _Options menu, advanced, there is the following path Rhino.Options.DefaultFileDialogDirectories.ExportDirectory
and I tought that this path is updated every time you export selected curves but only updates every time you open a Rhino file.

My goal is use the script to export a DXF file (solved) but compare the path from my rs.DocumentPath() and the path of the last exported in order to avoid mistakes saving the DXF files in a wrong path.

If last exported path (subpath) = rs.DocumentPath() then open last exported path, else open document path

This optimizes when you want to save multiple DXF curves with different names and do not want to select every time the subfolder. Same process when you use export selected curves from rhino option.

Solved how to access to Rhino.Options.DefaultFileDialogDirectories.ExportDirectory

Another option is after exporting a DXF file to save a txt in a specific path storing the string of the path, and every time I use the script compare the string included inside the txt file, but I think that this could be solved an easier way…

Solved in the last mentioned post.

Thank you so much for sharing and helping me with your knowledge.

is this scrypt would work but by group ?

To clarify - you are looking for a script which would export the all the objects in each group found in a file as a single .dxf?

each group save independently.

OK, I think that’s doable. Do you have a specific way you want to name the files? What about any objects that might not be in groups?

i would like to extract name of file from a block attribute, the idea is to export all parts i set for quotation as an idividual dxf. I already extract info from block with testexportblockattributes for my BOM. But i need to speed up my process of exporting each file for laser cutting.typical file

thank you

There are no groups in the file you posted above.

I found this in my library - it does not extract a name from a block, it simply asks you for a main file name and then numbers each group exported with that name plus a sequentially numbered suffix. Individual non-grouped objects are also exported as individual files. (2.8 KB)

thanks , ill try this.

wrong file sorry , this one