The objective is to create a movie of all the layer states in my model. About the time I get them all saved, something happens and I loose them all before I can get them added to the movie.
Thanks in advance.
David
The objective is to create a movie of all the layer states in my model. About the time I get them all saved, something happens and I loose them all before I can get them added to the movie.
Thanks in advance.
David
I just did a quick search:
Thank you Martin, the 36 layer states are already there. I just want images of the viewport, such as .png for each layer state arranged by 3 digit leading integer, e.g. 001-sample description thru 036-sample description
much appreciated
Yes I got that. The important bit of information I get out of that other topic is that apparently isn’t a way to retrieve the layer states with rhinoscriptsyntax.
The guide also does not have anything about Layer States.
The new Grasshopper Rhino components also don’t seem to have anything which retrieves the Layer States.
You don’t need to use RhinoScriptSyntax. It’ll be much easier to use RhinoCommon directly from Python.
You’ll be using NamedLayerStateTable Methods to get all the state names, then loop over those and restore each in turn. Then do a view capture with ViewCapture.CaptureToBitmap Method (ViewCaptureSettings) that you can save to file.
Yes, probably for good reason, as in a better way of accomplishing the objective
Wow! Awesome! Amazing!
Thanks for the links, especially. I’ll give it a whirl.
You can give this simple script a whirl. It saves all named layer states to the desktop folder as PNGs with the naming format [layerstatename]_layerstate_capture.png
. It uses the active viewport at time of starting of the script as well as the active display mode for that viewport.
batchrender_layerstates_to_desktop.py (1.1 KB)
#! python 3
# capture layer states in current viewport with current display mode
import scriptcontext as sc
import Rhino.Render as rr
import Rhino as r
import Rhino.DocObjects as rdob
import System
av = sc.doc.Views.ActiveView
def capture_viewport(name):
view_capture = r.Display.ViewCapture()
view_capture.Width = av.ActiveViewport.Size.Width
view_capture.Height = av.ActiveViewport.Size.Height
view_capture.ScaleScreenItems = False
view_capture.DrawAxes = False
view_capture.DrawGrid = False
view_capture.DrawGridAxes = False
view_capture.TransparentBackground = False
view_capture.RealtimeRenderPasses = 10
bitmap = view_capture.CaptureToBitmap(av)
if bitmap:
folder = System.Environment.SpecialFolder.Desktop
path = System.Environment.GetFolderPath(folder)
filename = System.IO.Path.Combine(path, name + "_layerstate_capture.png")
print("saving ", filename)
bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png)
for layer_state in sc.doc.NamedLayerStates.Names:
sc.doc.NamedLayerStates.Restore(layer_state, r.DocObjects.Tables.RestoreLayerProperties.All)
capture_viewport(layer_state)
Adapt for your needs
This forum never disappoints. I’ll have to wait until I get to feeling like sitting up a little better to give it a whirl.
Gotta go lie down now. Thanks a million, Nathan
I probably should too, it is 02:01 in the morning
You’re welcome (:
If I remember correctly, the version of MultiViewCapture plugin I posted a while ago apart from NamedViews also let’s you pick which LayerStates to capture:
Didn’t test it, but probably is good.
Anyway, the code I posted also serves only as the bare minimum base, good for learning purposes.
Worked like a charm. Thanks a million! Now, if I can get an .mp4 made of all those .PNGs on the desktop, I’ll submit it for consideration in the Gallery.
I always use Blender for my video editing needs. But any video editing software should do the trick.
My other tool I use is Camtasia