Skip to content

Scripting API

Named views

from ArtisanPlugin.Scripting import ViewApi as view

A named view is a camera angle stored inside the 3dm. These three methods are how a batch run reuses angles instead of recomputing them: save the angle once, restore it by name on every document, and - for documents that were never authored with your angles - import them from a template file first.

Unlike the rest of this facade, two of the three write into the document. RestoreNamedView only moves a camera; SaveNamedView and ImportNamedViews add entries to the document’s named-view table, which marks the file modified and means the change is only kept if the document is saved afterwards.

All three resolve the target viewport the same way as everything else here: viewport = None (or an empty/whitespace string) means the active view; a name is matched against the standard model viewports case-insensitively and trimmed; layout (page) viewports are not addressable. An unknown name throws ArgumentException - "Unknown viewport 'Persp'. Viewports: Perspective, Top, Front, Right." - and with no document open you get InvalidOperationException "No active document.", or "No active view." when nothing is active. ImportNamedViews has no viewport parameter at all: it works on the document’s table, not on a camera.

RestoreNamedView

view.RestoreNamedView(name, viewport = None)
ParameterDefaultMeaning
name-Name of a named view saved in the document, as listed by Describe()
viewportNoneViewport to restore it onto; None means the active one

Returns void. It moves the given viewport’s camera to the saved angle and redraws. No document mutation - the named view is read, not changed, so no Transaction is needed and no licence is checked.

An empty or whitespace name throws ArgumentException with "A named view name is required.". A name that is not in the document throws ArgumentException listing the real ones:

Unknown named view 'hero shot'. Named views: Hero, Side, Detail.

If the document has none at all the message ends Named views: (none). Note that, unlike viewport names, this lookup is Rhino’s own name search - take the spelling straight from Describe().

SaveNamedView

view.SaveNamedView(name, viewport = None)
ParameterDefaultMeaning
name-Name to store the angle under; an existing view of the same name is overwritten
viewportNoneViewport whose current camera is saved; None means the active one

Returns void. This one does change the document: it adds (or replaces) an entry in the named-view table. Wrap it in a Transaction when you want it to land as a single, clearly labelled undo step alongside the rest of your edits, and remember the angle is only persisted once the 3dm is saved. It requires a valid licence - the gate is checked before anything else happens.

An empty or whitespace name throws ArgumentException with "A name is required.". If Rhino refuses the entry you get InvalidOperationException - "Rhino could not save the named view 'Hero'."

from ArtisanPlugin.Scripting import ViewApi as view, Transaction

view.SetCamera(location, target, lensMm = 50, viewport = "Perspective")
with Transaction.Begin("Save hero angle"):
    view.SaveNamedView("Hero", viewport = "Perspective")

ImportNamedViews

view.ImportNamedViews(path)
ParameterDefaultMeaning
path-Path to a 3dm file whose named views you want copied in. Relative paths are resolved against the process working directory

Returns IReadOnlyList<string> - the names actually imported, in file order. A view whose name already exists in the active document is skipped, so the returned list is what changed, not what the template contained; an empty list means every angle was already there. The document’s own view always wins - importing never overwrites.

This changes the document (new entries in the named-view table), so it belongs inside a Transaction if you are grouping undo steps, and it needs a valid licence. It touches no camera and redraws nothing: after importing you still have to call RestoreNamedView to actually look through one of them.

It throws ArgumentException with "A 3dm file path is required." for an empty path, ArgumentException with "File not found: C:\templates\angles.3dm" (the resolved absolute path) when the file is missing, and InvalidOperationException with "Rhino could not read C:\templates\angles.3dm." when the file exists but is not a readable 3dm.

The batch recipe this exists for:

names = view.ImportNamedViews(r"C:\templates\render-angles.3dm")
print("imported:", ", ".join(names))

for angle in ("Hero", "Side", "Detail"):
    view.RestoreNamedView(angle)
    view.Capture(r"C:\out\%s.png" % angle, 1920, 1080)