Set activeview to top view

Hi,

I must set the activeview to the top view, and after get a capture to export the model from this view at jpg.

My doubt is, How Do I guarantee to set the view at top?

I’m working in c# with rhinocommon and with Spanish language, so i can´t use the field name to search the top view by name if I want translate the Plugin to others languages.

Thanks

1 Like

One way is to search for the localized Top viewport:

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      Rhino.Display.RhinoView view = null;

      view = doc.Views.Find("Top", false); // en
      if (null == view)
        view = doc.Views.Find("Superior", false); // es
      if (null == view)
        view = doc.Views.Find("Dessus", false); // fr
      if (null == view)
        view = doc.Views.Find("Superiore", false); // it
      if (null == view)
        view = doc.Views.Find("Drauf", false); // de
      if (null == view)
        view = doc.Views.Find("Shora", false); // cz
      if (null == view)
        view = doc.Views.Find("Góra", false); // pl

      if (null == view)
      {
        RhinoApp.WriteLine("Unable to find Top viewport.");
        return Result.Nothing;
      }

      doc.Views.ActiveView = view;

      return Result.Success;
    }

Just keep in mind that a viewport labeled “Top” does not necessarily display a top view.

1 Like

You could also check that the view is a parallel view and then compare the view direction to Array(0,0,-1).

That way you are future-proof for any language.

I have not done that before, nor used python yet, so it would take me some time to fiddle out the correct code, but I am sure @dale or any other wizard could hack it down pretty quickly.

1 Like

Thanks a lot

Yes, as a matter of fact, I would not even bother with view names, I would just set up the camera/target/projection, etc. the way you want it in the script. Views and viewports are notoriously hard to deal with in Rhino, given that viewport names can be different when localized and that the name of a viewport may not have anything to do with the actual view that’s in there…

–Mitch

I needed some code for this, and stumbled across this old discussion, so in case somebody (probably me again :smiley:) stumbles across this in the future, here is a simple code I made for this:

    # ---  CHECK IF VIEW IS A TOP VIEW
    view = rs.CurrentView()
    # --- ViewProjection == 1 is a parallel view
    if not rs.ViewProjection(view) == 1:
        print("This is a perspective view and not a top view")
        return
    target = rs.ViewCameraTarget(view)
    vector = target[1]-target[0]
    # --- The vector needs to be (0,0,-something)
    if vector.X == 0 and vector.Y == 0 and vector.Z < 0:
        print("View IS a top view")
    else:
        print("This is NOT a top view")
        return