Last active
June 16, 2018 17:17
-
-
Save pgolay/6090c7ceadb1257c937d4845db24f626 to your computer and use it in GitHub Desktop.
Stretches the view according to the aspect of a user set screen rectangle.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Rhino | |
import scriptcontext as sc | |
import rhinoscriptsyntax as rs | |
def GetBaseMode(): | |
""" | |
Making new display modes via RC seems to be broken | |
When that is fixed, this will help create the StretchView mode | |
if it does not exist. | |
""" | |
display_modes = Rhino.Display.DisplayModeDescription.GetDisplayModes() | |
if not display_modes: return Rhino.Commands.Result.Failure | |
go = Rhino.Input.Custom.GetOption() | |
go.SetCommandPrompt("Set a display mode to copy as a stretched mode.") | |
opt_list = [] | |
for i, mode in enumerate(display_modes): | |
english_name = mode.EnglishName | |
english_name = english_name.translate(None, "_ -,.") | |
opt_list.append( go.AddOption(english_name) ) | |
# Get the command option | |
go.Get() | |
if go.CommandResult()!=Rhino.Commands.Result.Success: | |
return None | |
selected_index = go.Option().Index | |
selected_description = None | |
for i,option in enumerate(opt_list): | |
if option==selected_index: | |
return display_modes[i] | |
def StretchView(): | |
modeName = "StretchView" | |
display_modes = Rhino.Display.DisplayModeDescription.GetDisplayModes() | |
if not display_modes: return Rhino.Commands.Result.Failure | |
mode_list = [] | |
for i, mode in enumerate(display_modes): | |
english_name = mode.EnglishName | |
english_name = english_name.translate(None, "_ -,.") | |
mode_list.append( english_name) | |
if modeName in(mode_list): | |
mode = display_modes[mode_list.index(modeName)] | |
else: | |
msg = ("Rhino could not find a display mode named " + modeName + ". \n" | |
+ "Please create a display mode named " + modeName +" and try again.\n \n" | |
+ "The name " + chr(34) + modeName + chr(34) + " has been copied to the clipboard for convenience.") | |
print msg | |
Rhino.UI.Dialogs.ShowMessageBox(msg, modeName) | |
rs.ClipboardText(modeName) | |
return | |
rc, rectangle, view = Rhino.Input.RhinoGet.Get2dRectangle(True) | |
if rc != Rhino.Commands.Result.Success: | |
return | |
pass | |
vp = view.ActiveViewport | |
if vp.IsPerspectiveProjection: | |
vp.ChangeToParallelProjection(True) | |
print "The viewport has been set to parallel projection." | |
#return | |
vp.DisplayMode = mode | |
ratio = rectangle.Width/rectangle.Height | |
mode.DisplayAttributes.ViewSpecificAttributes.HorizontalViewportScale = ratio | |
Rhino.Display.DisplayModeDescription.UpdateDisplayMode(mode) | |
sc.doc.Views.Redraw() | |
return Rhino.Commands.Result.Success | |
if __name__=="__main__": | |
StretchView() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment