Export stl with py script

Want to export object as stl file with incremental number and specific file location with py script please help

Hi

Does this post hel to get started:

thanks but want to export object with auto incremental number (it skips overwriting file)

Just a number? No file name at all?

like want to export sphere as part 001.stl and when i next running script for box it will be part 002.stl
(location of file is fixed)

Well, that would require somehow recording in the file or globally what the last used number was so it can be retrieved for the next run of the script. Not a real problem within the same Rhino session, but if you close and reopen that Rhino session it will revert to starting at 001 unless you store the last used number somewhere outside Rhino via a settings-type .ini file.

For the moment, to export multiple objects at one time I have this:
BatchExportSTLByObjBasic.py (1.1 KB)

However, it will start at 001 each time it is run.

thanks sir , is that possible if there is same file exist then it will add 1 number and then saved as new file with added number like if there is already file name part 001 exist then it will add 1 and save file as part 002 because location is fixed where file is saved. . .

You would have to do something like look at the file names in the folder, which can be done via I think System.IO. That’s something you can look up about Python in general, it’s not Rhino-specific. Of course there’s a bit of a problem here that if you’re exporting a bunch of STLs as auto-increment numbers, and just that…um you’re not going to know what the files are?

The Python os module will cover this.

#get all the files in a folder
for filename in os.listdir(folder):
    #select the ones with the desired extension
    if filename.lower().endswith(.stl):
      #do something