BUG - MacOS - View.Add Creates 0 width, 0 height view?

Hello,

I’m working on Cross Platform development for a new plugin and have no issue creating floating viewports on windows with some simple python code like this:

#! python3
import System
import Rhino
import scriptcontext as sc

def AddFloatingViewport():
    try:
        projection = Rhino.Display.DefinedViewportProjection.Perspective
        rect = System.Drawing.Rectangle(0, 0, 600, 600)
        new_view = Rhino.RhinoDoc.ActiveDoc.Views.Add("MyFloatingViewport", projection, rect, True)
        # new_view = sc.doc.Views.Add("MyFloatingViewport", projection, rect, False)
        # new_view = Rhino.RhinoDoc.ActiveDoc.Views.Add()

        shaded_id = Rhino.Display.DisplayModeDescription.ShadedId
        display_mode = Rhino.Display.DisplayModeDescription.GetDisplayMode(shaded_id)
        new_view.ActiveViewport.DisplayMode = display_mode

        new_view.Maximized = True
        new_view.ActiveViewport.ZoomExtents()

        new_view.Redraw()
        Rhino.RhinoApp.WriteLine(f"NewView Size: {new_view.Size}")
        Rhino.RhinoApp.WriteLine(f"Rect Size: {rect.Size}")
    except Exception as ex:
        Rhino.RhinoApp.WriteLine(f"AddFloatingViewport Exception: {ex}")

if __name__ == "__main__":
    AddFloatingViewport()

However, when ran on the MacOS via ScriptEditor I get a “RhinoView” but that RhinoView has a width and height of 0,0 respectively, regardless of what I set the “rect” variable to in the constructor.

Is this repeatable for anyone else? @wim @Gijs @eirannejad is this behavior present on your end with MacOS?

Result (Windows):
Floating viewport shows up maximized on main screen (if multiple monitors)

Print Statement (Windows):

NewView Size: {Width=1920, Height=1057}
Rect Size: {Width=600, Height=600}

Result (MacOS):
Floating viewport does not show up despite no errors being thrown

Print Statement (MacOS):

NewView Size: {Width=0, Height=0}
Rect Size: {Width=600, Height=600}

I have tested with IronPython2 as well and that seems to have the same issue.

Thank you all!

Yep. Weird. Trying a few things out now.

The viewport DOES get added on to the view list on the bottom on mac, always, but it never floats. Likely the size is 0,0 because it’s not been opened yet and hasn’t ever rendered.

There is a command NewFloatingViewport that can create one, so it is possible.

Thanks for looking into this @CallumSykes!

Correct, I checked that as well and running something like this from code works just fine:

import rhinoscriptsyntax as rs

rs.Command("_NewFloatingViewport _Projection Perspective")

So I agree, one CAN create floating viewports but apparently not correctly from the .Add method?

I would use the command to do it but I need more control over the viewport as the .Add method provides with it’s constructor arguments.

Apparently correct. I’ve just checked and the code explicitly does nothing on mac. So it will never make it floating on Mac when calling ViewTable.Add

1 Like

Let me youtrack this and then figure out if we can get you a workaround…

1 Like

https://mcneel.myjetbrains.com/youtrack/issue/RH-83813/ViewTable.Add-does-nothing-when-floating-is-set-to-true-on-Mac

1 Like

Thanks @CallumSykes,

Much appreciated!

FYI Setting the “Floating” argument boolean to True has no effect either… on my end at least.

Regardless of whether Floating=True or False, the width, height remain to be 0,0

Yes, I believe this makes a lot of sense. I’d expect it to make a floating frame, but it currently will not do anything. I’m having a crack at the code to see if I can make it do something.

1 Like

Thanks for looking into it!

Hi @CallumSykes , did you or @stevebaer happen to get a chance to poke around on this at all?

Curious if it’s a quicker workaround I can do in the meantime on my end to support Mac OS or if I need to wait for a proper bug fix on this one?

Thank you all!

I did some poking, but I haven’t fixed anything yet, I’m still a bit green on this low level part of Rhino.

You will likely need a proper fix from us on this one. That said, you can try and create a workaround using that command and then manipulating the floating view.

1 Like

Thanks @CallumSykes , I appreciate the response and looking into it!

Unfortunately I’ll need the full argument logic outside of just the rhinoscriptsyntax commands so I will eagerly await a response/fix and occasionally “poke” and eagerly check in on the progress of that :slight_smile:

1 Like

By the way in case anyone needs a workaround, the following code will work on both windows and mac to create a floating viewport:

OS = "MacOS" if Rhino.Runtime.HostUtils.RunningOnOSX else "Windows"

            view_rectangle = System.Drawing.Rectangle(self.Location.X, self.Location.Y,
                                                    self.Size.Width, self.Size.Height)
            if OS == "Windows":
                # print("Using Windows OS method of viewport creation")
                # This doesn't work on Mac OS
                self.viewport = Rhino.RhinoDoc.ActiveDoc.Views.Add(
                    "MyFloatingViewport",
                    Rhino.Display.DefinedViewportProjection.Perspective,
                    view_rectangle,
                    floating=True)

            else:
                # print("Using Mac OS method of viewport creation")
                # Test work around for 0 height, 0 width Mac OS viewport bug
                rs.Command("_NewFloatingViewport _Projection Perspective")  # This works on Mac OS
                viewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport
                viewport.Name = "MyFloatingViewport"
                viewport.ScreenRectangle = view_rectangle
                self.viewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView
1 Like