Create New file & layers with Python

I found this deom @Helvetosaur for creating a new Rhino file.

mport rhinoscriptsyntax as rs

#Note - this will close the document without saving!!
rs.DocumentModified(False)
rs.Command("_-New _None")

Is there a way to do this and also delete / Purge default layers and add my own layer structure.

or an auto run script when opening a new file.

Thanks, Randy

Sounds like you don’t really need a script

Set your file up with your layer structure and then run the SaveAsTemplate command.

Next time you start a New File, there’s a checkbox to always use the selected template for new files (at least in Windows!) :wink:

GM

I don’t know when I might have posted that… Anyway, MacRhino’s “unique” MDI unfortunately makes it relatively useless for a number of things, including certain types of file operations and batch processing. As New always creates a new window in MacRhino, if you are running a script in the original window, there’s absolutely nothing you can do with it in the new window. Well, maybe not absolutely nothing, I suppose there might be some way via RhinoCommmon and RhinoDoc.ActiveDoc to be able to do some stuff in the new window via the script running in the original window, but that’s pretty complicated…

Running a startup script is possible in Windows Rhino, but not in MacRhino yet, and anyway, that’s only when Rhino itself starts, not when a new file is opened.

So, as gm says, the best is to create a custom template with the stuff you need already in it and use that.

–Mitch

Thanks @Helvetosaur and @gmacarchitect I forgot you could setup custom Template files as “Default” with OSXRhino. It seems lately I need various versions of files, different renders with filleted edges and materials etc… I am usually working from an open file and seem to bypass the Welcome Window.

There is a problem with saving Template files and it seems Marlin will have it fixed in next WIP.

Randy

@Helvetosaur, if I remember it was Aug 2013, the date on the post.