RhinoPageView on a headless document

I’m basically trying to create a layout view on a headless rhino document.

  • created a headless document
  • used var view = doc.Views.AddPageView(“name”, 297, 210); //doc is the headless document.

now testing view to see if it’s null and it is.

I tried writing the file to an actual 3dm file and opened it, it gives me a standard rhino view (not a layout) with “name”.

GetPageViews.Length is zero whatever I do.

Note: my process works fine on a regular rhino file.

Hi @mo7ammad11,

Can you provide the source code to what isn’t working for you, so I can repeat what you are seeing?

– Dale

Hi @dale , thanks for stepping in to help.

so I’m trying to repeat this but with a headless document.

BoundingBox bbx = bb.BoundingBox;//bounding box for zooming
Guid id = Guid.Empty;
Rhino.Display.RhinoPageView pageview = null;
Rhino.DocObjects.DetailViewObject detail = null;

var page_views = doc.Views.GetPageViews();
int page_number = (page_views == null) ? 1 : page_views.Length + 1;
pageview = Rhino.RhinoDoc.ActiveDoc.Views.AddPageView(string.Format("A4_{0}", page_number), 297, 210);

if (pageview != null)
  Print("creating pageView");
  id = pageview.ActiveViewportID;
  Rhino.Geometry.Point2d top_left = new Rhino.Geometry.Point2d(bl.X, bl.Y);
  Rhino.Geometry.Point2d bottom_right = new Rhino.Geometry.Point2d(tr.X, tr.Y);
  detail = pageview.AddDetailView("ModelView", top_left, bottom_right, Rhino.Display.DefinedViewportProjection.Top);


I’m having the exact same problem, @dale do you have any news on this?

I also tried running the same code on OSX and there it actually does create a new Layout view in headless mode, but I cannot set the size and name of the Layout. The issue on OSX has already been described here.

Sample Code:

import Rhino
import scriptcontext as sc

path = '/Path/To/Output/headless_test.3dm'

# Make new doc
test_doc = sc.doc.CreateHeadless(None)

# Add some example data
sample_text = Rhino.Geometry.TextEntity()
sample_text.Plane = Rhino.Geometry.Plane.WorldXY
sample_text.Text = "Hello Rhino!"
sample_text.Justification = Rhino.Geometry.TextJustification.MiddleCenter
sample_text.FontIndex = test_doc.Fonts.FindOrCreate("Arial", False, False)

# Create Layout
test_doc.PageUnitSystem = Rhino.UnitSystem.Millimeters
pageview = test_doc.Views.AddPageView("LayoutTest", 200, 200)

# Save
opts = Rhino.FileIO.FileWriteOptions()
test_doc.Write3dmFile(path, opts)
test_doc = None


Tested with the latest Version 7 (7.8.21196.05002, 2021-07-15)


Hi @valentin1, @mo7ammad11,

There are a couple of things going on here. I’ve opened an issue.


– Dale


@stevebaer @dale
I am also facing the above issue, Is there any alternate way to import a Layout in headless mode.
Please update since its blocking in developing a plugin in rhino 7.

Hi @vijaysarathy,

The ImportLayout command will imported selected layouts into the current document. We can probably expose this to RhinoCommon and have it work on headless documents (too).


– Dale