Beginner python question: can someone provide a example exporting stl in a python script

I’ve been using python for rhino on a mac. I am wondering if someone could show me an example of how to call Export from python. I’d like to duplicate the functionality of this export by layer rhinoscript:

I would be grateful for any help.


Hi Craig,

This script will work on Windows Rhino: (499 Bytes)

import rhinoscriptsyntax as rs

layers = rs.LayerNames()
splitLayers = []
for layer in layers:
    split = layer.split("::")

for layer in splitLayers:
    ids = rs.ObjectsByLayer(layer)
    if ids:
        selIds = ""
        for id in ids:
            selIds = selIds + "_SelId " + str(id) + " "
        commandString = "-_Export " + selIds + " _Enter " + chr(34) + layer + ".stl" + chr(34) + " _Enter " + "_Enter"

Have no idea whether or not it will work on Mac too, as I have never used that Rhino version.

@djordje, Thank you very much!
The commandString idea is a clever tool that I can use again.