I’m trying to create a python code using RhinoCommon to do multiple Rhino commands at once.
NewFloatingViewport Projection Perspective
MaxViewport
Zoom Extents
SetDisplayMode Mode Shade
I think the following code makes it to step 2, MaxViewport, but I can’t seem to complete the rest quickly. Can someone help? I don’t want to use rhinoscriptsyntax.Command(), because it made my Grasshopper file very unstable executing multiple commands.
import rhinoscriptsyntax as rs
import Rhino
import System
from scriptcontext import doc
if r:
newView = Rhino.RhinoDoc.ActiveDoc.Views.Add("Test", Rhino.Display.DefinedViewportProjection.Perspective, System.Drawing.Rectangle(0, 0, 600, 600), True)
newView.Maximized = True
I could make it work, sort of… This will change display mode of all views. How can I change the display mode of only the newly created floating viewport? Thank you.
import Rhino
import System
import scriptcontext as sc
import rhinoscriptsyntax as rs
if r:
#Create a new floating view
newView = Rhino.RhinoDoc.ActiveDoc.Views.Add("TEST", Rhino.Display.DefinedViewportProjection.Perspective, System.Drawing.Rectangle(0, 0, 600, 600), True)
#Maximize a view
newView.Maximized = True
#Zoom extents
rs.ZoomExtents
#Set display mode
views = rs.ViewNames()
for view in views:
rs.ViewDisplayMode(view, "Shaded")
Can someone please let me know why the revised code below doesn’t work? It doesn’t change the display mode… I checked view name to see if Current view is set correctly, and it seems right.
import Rhino
import System
import rhinoscriptsyntax as rs
if r:
#Create a new floating view
newView = Rhino.RhinoDoc.ActiveDoc.Views.Add("TEST", Rhino.Display.DefinedViewportProjection.Perspective, System.Drawing.Rectangle(0, 0, 600, 600), True)
#Maximize a view
newView.Maximized = True
#Zoom extents
rs.ZoomExtents
#Set display mode
view = rs.CurrentView("TEST")
viewName = rs.CurrentView(return_name = True)
print viewName
rs.ViewDisplayMode(view, "Shaded")
Hi Dale,
Thank you so much for your answer, but I somehow don’t get “Add” method after “sc.doc.Views.”. There is “AddPageView” available, and I get the error message below.
Solution exception:‘GhViewTable’ object has no attribute ‘Add’
Can you let me know what the issue is?
Yes, I’m using Rhino 6, but I need to run it in Grasshopper. It’s part of much larger Grasshopper file. Is there a way to modify your script to run in Grasshopper?