Hi all
Sharing is caring, so I thought I would share a few things. Firstly, a script that made my life a lot simpler. Imagine you have to produce a lot of details, all in 2D, but you would like to put them all on a separate layout.
Now you can make a rectangle curve, give it a name and the script will generate all layouts for you, keeping the name, making the size 1:1 and applying a detail view focusing on that specific frame. Have a look at the video:
Code is here:
# Author: Pawel Jakub Tujakowski / kumulus.agency
# Version: 1.0
# Date: 2024.02.14
# layouts_from_named_curves.py 2024 by Pawel Jakub Tujakowski is licensed under Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)
import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs
def layouts_from_named_curves():
### VARIABLES RESET###
frameNames = []
frameNamesCheck = []
frameBoxLL = []
frameBoxUR = []
v=0
i=0
layouts = []
layoutNames = []
### SCRIPT WORKS IN MM ###
sc.doc.PageUnitSystem = Rhino.UnitSystem.Millimeters
### PICK CURVES FOR FRAMES ###
frameIds = rs.GetObjects("Pick frames", rs.filter.curve)
if frameIds == None:
return()
### GET ATTRIBUTES FOR EACH FRAME ###
for id in frameIds:
frameName = rs.ObjectName(id)
frameNames.append(frameName)
frameNamesCheck.append(frameName)
frameBox = rs.BoundingBox(id)
frameBoxLL.append(frameBox[0])
frameBoxUR.append(frameBox[2])
### CHECK IF FRAMES HAVE A NAME ###
if frameName == None:
rs.MessageBox("ERROR: All frames must have names", 0|48)
return()
### CHECK IF FRAMES NAMES ARE QNIQUE AND ARE NOT ALREADY IN USE###
for v in sc.doc.Views:
Rhino.Display.RhinoPageView
if type(v) is Rhino.Display.RhinoPageView:
layouts.append(v)
frameNamesCheck.append(v.PageName)
if len(frameNamesCheck) != len(set(frameNamesCheck)):
rs.MessageBox("ERROR: Duplicate names found. Provide unique layout and/or frame names.", 0|48)
return()
### IF EVERYTHING IS OK, CREATE LAYOUTS ###
for frameName in frameNames:
sizeX=frameBoxUR[i].X-frameBoxLL[i].X
sizeY=frameBoxUR[i].Y-frameBoxLL[i].Y
midX=(frameBoxUR[i].X-frameBoxLL[i].X)/2+frameBoxLL[i].X
midY=(frameBoxUR[i].Y-frameBoxLL[i].Y)/2+frameBoxLL[i].Y
page_views = sc.doc.Views.GetPageViews()
pageview = sc.doc.Views.AddPageView(frameName,sizeX, sizeY)
pageview.SetPageAsActive()
sc.doc.Views.ActiveView = pageview
sc.doc.Views.Redraw()
if pageview:
detail = pageview.AddDetailView("Top_view", Rhino.Geometry.Point2d(0,sizeY), Rhino.Geometry.Point2d(sizeX,0), Rhino.Display.DefinedViewportProjection.Top)
if detail:
pageview.SetActiveDetail(detail.Id)
detail.Viewport.SetCameraTarget(Rhino.Geometry.Point3d(midX,midY,0), True)
detail.CommitViewportChanges()
detail.DetailGeometry.IsProjectionLocked = True
detail.DetailGeometry.SetScale(1, sc.doc.ModelUnitSystem, 1, sc.doc.PageUnitSystem)
detail.CommitChanges()
i=i+1
if __name__ == "__main__":
pageview = sc.doc.Views.ActiveView
if type(pageview) == Rhino.Display.RhinoPageView:
print "This tool only works in the model space."
else:
layouts_from_named_curves()
Link to the file:
https://www.dropbox.com/t/28Ez30Mgelb18tcn
Enjoy