Python Scripting Export

Is there a method for doing a simple file export without using “Command”?


Last I did this I used Command like this:

rs.Command("_-Export “+chr(34)+str(saveFolder)+chr(92)+str(name)+”.3ds"+chr(34)+" _Enter" ,False)

Names and adresses has to have " coded in if there are spaces in the name. Also avoid odd characters like the Norwegian æøå.

Hope that helps, or are there any other reason you can’t use Command?

Sorry, no.

I like to add a more Pythonic alternative to this line, to make it more human readable (in a way) and more versatile:

import rhinoscriptsyntax as rs

save_folder = 'D:\\Temp' #double \\ to represent a single \  is a python quirck
file_name = 'Filename'
extension = '.3ds'

# strings can be encapsulated between either ' ' or " "
# using ' ' leaves the " free for to use inside the string
# {} in a string is a placeholder that can be filled by the format method
# numbers inside refer to the index position of the arguments passed
comm_string = '_-Export "{0}\\{1}{2}" _Enter'

print comm_string.format(save_folder,file_name,extension)

#This makes it easier to export to various formats for example
extensions = ['.3ds','.dxf','.dwg']

#Select objects for export
for extension in extensions:
    print comm_string.format(save_folder,file_name,extension)

More format examples:


Well… I am not sure you nailed that aspect, but the code is pretty and sure is versatile :wink:

Indeed the readability declined once I decided to add the formatting :laughing:

The initial readability improved somewhat when I though of this:

'_-Export "' + save_folder + '\\' + file_name + extension + '" _Enter'