Hello,
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))
rs.CurrentView(layoutName)
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.CurrentView(layoutName)
rs.UnselectAllObjects()
rs.SelectObject(detail_id)
rs.Command('-Detail Enable ', echo=False)
rs.UnselectAllObjects()
detail_obj = rs.coercerhinoobject(detail_id)
viewport = detail_obj.Viewport
viewport.ZoomExtents()
detail_obj.DetailGeometry.IsProjectionLocked = True
detail_obj.DetailGeometry.SetScale(1.0, Rhino.UnitSystem(4), 0.02, Rhino.UnitSystem(4))
detail_obj.CommitChanges()
doc.Views.ActiveView.SetPageAsActive()
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.Redraw()
rs.Command('-Detail EnablePage ', echo=False)
rs.UnselectAllObjects()
if __name__ == "__main__":
NewLayout(paper_size['A0'])