Hello ,
I need create a windows form with Rhino viewport, Any idea how I can make this ??
Thanks
Hello ,
I need create a windows form with Rhino viewport, Any idea how I can make this ??
Thanks
Hi @MatrixRatrix,
RhinoCommon does not provide a way of embedding a full-featured viewport into a form or dialog.
However, Rhino.UI has a simple view-only control - 'Rhino.UI.Controls.ViewportControl`. Here is a simple example of how to use it.
ā Dale
Hi @dale , and add layout viewport ? is possible ?
Thanks
Hi @MatrixRatrix,
Sure. To add a layout, you can either script the -Layout
command, or use the ViewTable.AddPageView
RhinoCommon method.
ā Dale
@dale ,
This Add layout on form?? if so, how?
No, this adds a layout to the document.
ā Dale
Another feature that would solve the problem would be to be able to orbit the model in the main viewport.
Thanks
Sure, just do something like this:
m_viewport_control.Viewport.DisplayMode = mode;
m_viewport_control.Refresh();
where:
m_viewport_control
= Rhino.UI.Controls.ViewportControl
mode
= Rhino.Display.DisplayModeDescription
ā Dale
I need the ETO dialog box to lose focus and let me zoom and rotate in Rhinoās main viewport.
It would be better than having the viewport inside the ETO.
Why the viewport control embed in plugin dialog display the same as model in Rhino Viewport?,is this a bug?
Hi @dale, is it possible to set the projection in the viewport, say Top?
Iām trying with
mode = Rhino.Display.DisplayModeDescription.FindByName('Shaded')
proj = Rhino.Display.DefinedViewportProjection.Top
viewport0 = Rhino.UI.Controls.ViewportControl(Size = drawing.Size(400, 400))
viewport0.Viewport.DisplayMode = mode
Rhino.UI.Controls.ViewportControl.Viewport.PropertyType.SetProjection(viewport0, proj,'viewname', False)
viewport0.Refresh()
to set the projection, but ViewportControl doesnāt like that, so Iām guessing if there is another way to set projection for ViewportControl
And I couldnāt find Rhino.UI.Controls.ViewportContrls
in the namespace window to the left of the python editor screen
Thanks for the advice.
Actually, I think I stumbled across the solutionā¦
SetProjection works for a Rhino Viewport, not ViewportControl
So I changed the code to this: (I used the 2 print statements to tell me the type of each)
mode = Rhino.Display.DisplayModeDescription.FindByName('Shaded')
proj = Rhino.Display.DefinedViewportProjection.Top
viewport0 = Rhino.UI.Controls.ViewportControl(Size = drawing.Size(400, 400))
viewport0.Viewport.DisplayMode = mode
#print viewport0.Viewport.DisplayMode
#print viewport0.Viewport
viewport0.Viewport.SetProjection( proj, '', False)
I tried this code, even modified it a bit wit success, but every time I run it it adds two viewports to the lisf of viewports in my Rhino document. I didnāt find a way to delete these viewports as I close the Eto window. As you might imagine the mess quickly piles up, because each script run adds 2 unnecessary viewports.
How can I delete these viewports (or even better - do not create them at all) as I close the Eto window?
Hi @moby-dk ,
Same issue here on my end using a Rhino.UI.Controls.Viewport Control in R8 with Python 3 and same issue reported here as well:
I canāt say that Iām glad you have the same problem, but maybe it will gain more developersā attention since it affects more users. Thanks for the links, I didnāt know about these posts.
haha right, agreed.
The irony for me is that the āpopup viewportsā we donāt want to see actually have the full featured capability of a Rhino viewport that I WANT to embed into Eto.
The Rhino.UI.Control.ViewportControl that does get embedded into Eto really acts more like a viewer and not a full featured Rhino.Viewport.
While I think this is a relevant thing to have, a full featured, embeddable Rhino.Viewport within an Eto.Form is really what I would like to have for my developments.
When youāre form is closing, do something like this (note - I have not tried this):
var viewport = myViewportControl.Viewport
if (null != viewport)
{
var parentView = viewport.ParentView;
if (null != parentView)
parentView.Close();
ā Dale
Hi @dale,
I attempted to utilize that idea here but it gives None as a Parent:
def OnFormClosed(self, sender, e):
# Close Rogue Viewports
try:
if self.viewport_control is not None:
vpc_viewport = self.viewport_control.Viewport
# Get the parent view of the viewport
vpc_parent = vpc_viewport.ParentView
# Print the parent view
if vpc_parent:
vpc_parent.Close()
Rhino.RhinoApp.WriteLine("Parent View: " + vpc_parent.MainViewport.Name)
else:
Rhino.RhinoApp.WriteLine("No parent view found.")
except Exception as ex:
Rhino.RhinoApp.WriteLine(f"Close Viewports: {ex}")
When executing a script that creates a viewport control and running this statement to print the active viewports in the model you can see that Custom view shows up:
if __name__ == '__main__':
CreateMainForm()
# Get all open views in the document
views = Rhino.RhinoDoc.ActiveDoc.Views
# Iterate through each view and print the viewport names
for view in views:
viewport = view.ActiveViewport
Rhino.RhinoApp.WriteLine("Viewport Name: " + viewport.Name)
Print Statement:
Viewport Name: Perspective
Viewport Name: Top
Viewport Name: Front
Viewport Name: Right
Viewport Name: Custom view
This code does seem to properly close the āextra duplicateā viewport on form close (though this would also close a āvalidā Custom view if applicable outside of the Eto.Form as well (if someone added a custom floating view from Rhino for instance):
# Form Class Initialization Code Above This ^
def OnFormClosed(self, sender, e):
# Close Rogue Viewports
try:
if extra_views:
for view in extra_views:
view.Close()
except Exception as ex:
Rhino.RhinoApp.WriteLine(f"Close Extra Viewports: {ex}")
def CheckViewports():
extra_views = []
# Get all open views in the document
views = Rhino.RhinoDoc.ActiveDoc.Views
# Iterate through each view and print the viewport names
for view in views:
viewport = view.ActiveViewport
if viewport.Name == "Custom view":
extra_views.append(view)
Rhino.RhinoApp.WriteLine("Viewport Name: " + viewport.Name)
return extra_views
if __name__ == '__main__':
extra_views = CheckViewports()