Aligning Detail views with regard to model coordinates on a layout


I couldn’t find a topic that exactly address the subject I’m having trouble so I’m starting a new one, sorry in advance if I miss.

The gist here is to move a DetailView within a Layout from the projected origin to an arbitrary point on the Layout. To do that, I’m using Rhino.Display.RhinoViewport.WolrdToClient method but the point doesn’t match the origin.

Is there another/simpler way to align DetailView with regard to model coordinates?

Here’s a quick example:

# coding: utf-8
import scriptcontext as sc
import rhinoscriptsyntax as rs
import Rhino
import Rhino.Geometry as rg

doc =  sc.doc
paper_size = {'A0': [1188.0,841.0]}

def NewLayout(size):
    layoutName = rs.AddLayout("Layout", size=(size))
    detail_c1 = rs.coerce2dpoint((450,438))
    detail_c2 = rs.coerce2dpoint((2137,777))
    detail_id = rs.AddDetail(layoutName, detail_c1, detail_c2, projection=5)
    set_detail(layoutName, detail_id, size)

def set_detail(layoutName, detail_id, size):
    rs.Command('-Detail Enable ', echo=False)

    detail_obj = rs.coercerhinoobject(detail_id)
    viewport = detail_obj.Viewport
    detail_obj.DetailGeometry.IsProjectionLocked = True
    detail_obj.DetailGeometry.SetScale(1.0, Rhino.UnitSystem(4), 0.02, Rhino.UnitSystem(4))
    pageview  = doc.Views.ActiveView
    line = rg.Line(rg.Point3d(0, size[1]/2, 0), rg.Point3d(size[0], size[1]/2, 0))
    origin_2d = pageview.MainViewport.WorldToClient(rg.Point3d(0,0,0))
    vec = line.PointAt(0.5) - rg.Point3d(origin_2d[0], origin_2d[1], 0)
    rs.MoveObject(detail_id, vec)
    rs.Command('-Detail EnablePage ', echo=False)

if __name__ == "__main__":

Stating my problem in simpler terms, I want to script this action:

The first uses the Move command to move the details by a significant point on the model to a reference line on the layout.

It seems like something many people would want to do but I couldn’t find anything despite my searching.

Hi @ju_anoriant,

With a detail view active, you can obtain the proper world-to-page-layout transformation using DetailViewObject.WorldToPageTransform.

– Dale

Hi @dale

Thanks for the reply, I eventually found a way to make it work, but at first I wasn’t aware of the importance of activating the right view/detail before executing any command. Context is everything, now I know :smile: