Hi,
How can I programatically get the set of viewports those I can made active in a particular view? To be more specific, there is always a set of four viewports at the bottom of a view (in the app). How can I get that set of viewports?
Arif
Hi,
How can I programatically get the set of viewports those I can made active in a particular view? To be more specific, there is always a set of four viewports at the bottom of a view (in the app). How can I get that set of viewports?
Arif
Hi Arif,
Are you writing in C++ or .NET (e.g. RhinoCommon)?
in .Net
How about this?
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var standard_views = doc.Views.GetStandardRhinoViews();
foreach (var view in standard_views)
{
RhinoApp.WriteLine(view.ActiveViewport.Name);
}
return Result.Success;
}
Hi Dale,
Thanks a lot. That worked fine
Arif
I tried this method of listing views and I get only the ones currently visible:
Perspective
Top
Front
Right
When I set the Top view as Bottom in the UI I get:
Perspective
Bottom
Front
Right
What I want to do is set the Bottom view as the active in code but when I do the following, I get a null:
var tempView = Doc.Views.Find("Bottom", false);
Doc.Views.ActiveView = tempView;
I think I am missing a step along the way, please let me know.
Best;
Steve
This simple script works here in Rhino 7:
import Rhino
import scriptcontext as sc
def test_standard_views():
active_view = sc.doc.Views.ActiveView
if active_view:
print(active_view.ActiveViewport.Name)
standard_views = sc.doc.Views.GetStandardRhinoViews()
print("Standard view count = {0}".format(len(standard_views)))
for view in standard_views:
print(view.ActiveViewport.Name)
botton_view = sc.doc.Views.Find("Bottom", False)
if botton_view:
print("Bottom view found!")
sc.doc.Views.ActiveView = botton_view
test_standard_views()
– Dale
I must not have something setup up correctly. I had to change the code to this for C#:
var active_view = doc.Views.ActiveView;
RhinoApp.WriteLine(active_view.ActiveViewport.Name);
var standard_views = doc.Views.GetStandardRhinoViews();
foreach (var view in standard_views)
RhinoApp.WriteLine($"Active Viewport Id: {view.ActiveViewport.Name}");
var botton_view = doc.Views.Find("Bottom", false);
if (botton_view != null)
{
RhinoApp.WriteLine("Bottom view found!");
doc.Views.ActiveView = botton_view;
}
else
{
RhinoApp.WriteLine("Bottom view not found!");
}
Running this I get this is output:
Perspective
Active Viewport Id: Perspective
Active Viewport Id: Top
Active Viewport Id: Front
Active Viewport Id: Right
Bottom view not found!
I am running this just after Rhino loads. I have not selected the bottom view from the UI. Is there a setup step that needs to be taken before doc.Views.GetStandardRhinoViews() will return all of the views including the bottom?
Let me know if this code is returning all of the views on your end. I have attached the test project I used to verify.
Thanks for the help!
Steve
CSProjectTemplate1.zip (121.4 KB)
Should have included the version of Rhino i am using:
n— Rhino Version
1) Major <—> 7
2) Minor <—> 7
3) Build <—> 21160
4) Revision <—> 5001
Best;
Steve
Hey @slyon,
If you read the output of the script, you’ll see that you don’t have a bottom view. Try running the SetView
command and then re-run the script.
– Dale
Are you saying rhino common api does not have a method to set the bottom view as current? If so this solves my missing step. I thought GetStandardRhinoViews would actually include all views. It must only include the active views in the ui. So when the ui shows all default views this code is not part of the public release. Makes sense, let me know if my assumption it is wrong.
OK, I will go a different way on the test framework I am building for this plug-in.
Thanks
Best
Steve
What I am saying Rhino, by default, has four standard views and none of them are set to ‘bottom’.
No. A view is the actual window you see on your screen.
If you want to set a view’s project to something ‘standard’, use RhinoViewport.SetProjection.
import Rhino
import scriptcontext as sc
view = sc.doc.Views.ActiveView
if view:
print(view.ActiveViewport.Name)
proj = Rhino.Display.DefinedViewportProjection.Bottom
view.ActiveViewport.SetProjection(proj, "Bottom", True)
view.Redraw()
– Dale
Cool… in everything I have looked at in the past couple of days SetProjection, DefinedViewportProjection was never mentioned. This probably goes to not asking the question in the correct way but I am very happy we got to a solution.
Best;
Steve
One last question on this topic. Is there a get function that will return the DefinedViewportProjection for the ActiveViewport?
complement to:
activeView.ActiveViewport.SetProjection(definedViewportProjection, null, true)
The only thing I can find to match this up is the view port name and I would like to use the Rhino.Display.DefinedViewportProjection value if I can. This will allow me to save off the current projection value, set a new projection then set it back after the test is complete.
Steve
No.
The DefinedViewportProjection
enum lists the pre-defined view projections that Rhino can set to a view. Once set, all you have to do is nudge the view in some way (pan, zoom, rotate, etc.) for the current view project to no longer matchup with the pre-defined one. And we don’t have a way of comparing to see if a view project is “close to equal” to a pre-defined one.
– Dale
Makes sense! Thanks for all the help.
Best;
Steve