How to "redraw" the viewportControl

Hi all,
I have a ETO UI with a viewportControl. I need the viewportControl camera to be set programatically, similar to rhino’s savedView user experience…

I managed to set the viewportControl’s viewport’s camera (location, direction and lens values) but I can’t figure out how I can refresh the viewport. In other projects I have used the RhinoView’s Redraw() method, but since I’m working with viewportControl, there is no RhinoView for “redrawing”.

How can I “refresh” or “redraw” the viewport of a viewportControl?

    def onRestoreItemClick(self,sender,e):
        try:
            selectedIndex = self.viewListBox.SelectedIndex
            selectedView = self.viewModel.views[selectedIndex]
            self.vp.Viewport.SetCameraLocation(selectedView.location,False)
            self.vp.Viewport.SetCameraDirection(selectedView.direction,False)
            self.vp.Viewport.Camera35mmLensLength = seletectedView.lens
            self.vp.Refresh() #NO LUCK WITH REFRESH...THIS IS NO REDRAWING NOTHING
        except Exception as e:
            Rhino.RhinoApp.WriteLine(str(e))

Invalidate is typically what you call on UserControls in WinForms

is this what you are looking for ?
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Display_RhinoView_Redraw.htm

thanks @stevebaer, UTO’s control class also have a Invalidate method, not sure is its function is the same as winforms, they certainly “look similar”

ETO: Invalidate(): Queues a repaint of the entire control on the screen and any of its children.
WINFORMS: Invalidate(): invalidates a specific region of the control and causes a paint message to be sent to the control.

Anyway, I tried Invalidate() but no success. I need to slightly move the camera by hand to see the restored camera position. I tried invalidating the MainForm and also invalidating the viewportControl itself without luck

is this what you are looking for ?
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Display_RhinoView_Redraw.htm

No, unfortunately “viewportControl” is not child of RhinoView at the contrary of the “regular” viewport, so Redraw() method doesn’t apply it that case…

Hi @aitorleceta,

without some running code it is hard to help. I can repeat what you see with below example and the self.vpc.Invalidate() line commented out:

import scriptcontext
import Rhino.UI
import Eto

class SimpleEtoDialog(Eto.Forms.Dialog):
    def __init__(self):
        self.ClientSize = Eto.Drawing.Size(500, 500)
        self.vpc = Rhino.UI.Controls.ViewportControl()
        self.button = Eto.Forms.Button(Text="Click")
        self.button.Click += self.TestSetViewport
        self.layout = Eto.Forms.DynamicLayout()
        self.layout.AddRow(self.button)
        self.layout.AddRow(self.vpc)
        self.Content = self.layout
        
    def TestSetViewport(self, sender, e):
        target_location = Rhino.Geometry.Point3d(0,0,0)
        camera_location = Rhino.Geometry.Point3d(100, 100, 50)
        self.vpc.Viewport.SetCameraLocations(target_location, camera_location)
        self.vpc.Viewport.Camera35mmLensLength = 20.0
        #self.vpc.Invalidate()

dialog = SimpleEtoDialog()
dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)

Once i enable the commented line, it seems to update. While testing i found out that i can make the ViewportControl update using this too:

self.vpc.Enabled = False
self.vpc.Enabled = True

It also seems to update by changing self.ClientSize. Do you see the same with above example ?

_
c.

self.vpc.Enabled = False
self.vpc.Enabled = True

This is working! thanks @clement !

Efectively your code is working fine also here, so the problem seem to be in my code. Sorry, for not taken the time to make more test myself, like you did.

I’m using a tablelayout and the viewportControl is inside a Cell. Don’t know, but maybe is related with the fact that Invalidate() is not working in my code?

anyway, thanks to all, problem solved!

Hi @aitorleceta, i can repeat that here with a TableLayout. Somehow i have different problems when Controls are put into various containers. Eg. if i have a Eto.Forms.GridView having GridLines enabled, the lines appear as they should. As soon as i put this GridView into a Splitter, the thickness of the GridLines is more than doubled.

I hope @curtisw is reading this and can shed some light…

_
c.

1 Like