RSS

Rhino C# Development (V) : Create and dock Rhino Panels side-by-side

12 Jun

In my previous blog Rhino C# Development (III) : Add Winform UI to Rhino, I demonstrated how to create a dock bar with Winform User controls in Rhino3D.

In this blog I am to demonstrate how to use a similar approach to create Rhino panels, and then dock the panels side-by-side. Rhino panels, are tabbed containers where collection of controls can be hosted, as shown below.

tabbedpanel-001.png

To create such a panel, in Visual Studio, add a user control in the plugin project. If you don’t know how to create such a plugin project, refer to my previous blogs for details.

In this example, a UserControl called GeometryPanel is inserted into the project, and a few simple winform controls are added for illustrative purposes. Add a Guid attribute to the UserControl, as shown below.
 image

[System.Runtime.InteropServices.Guid(0b0c3a6e-7efb-47c9-b2e3-7d92788a9f74)]
public class MyPanelCommand : Command
{
    public MyPanelCommand()
    {
        Instance = this;
    }
}

 

Next, in the rhino command class, add below code lines:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    var type = typeof(GeometryPanel);
    Rhino.UI.Panels.OpenPanel(type.GUID);
    return Result.Success;
}

Build and Run. You will see nothing if your run your command in Rhino3D. Fear not. We missed an important step: to register this panel with Rhino! In the rhino plugin class, in the constructor function, add below code lines:

public MyPanelPlugIn()
{
    Instance = this;
    Rhino.UI.Panels.RegisterPanel(this, typeof(GeometryPanel), Geometry,
        P
roperties.Resources.Geometry);
}

Rebuild and run! Yeah! When we run the command, we can see our user control based panel inside Rhino3D!

image

OK, let’s walk one step further. Let’s dock our panel side by side with Layers Panel, to do so, modify the RunCommand function above as follows:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    var type = typeof(GeometryPanel);
    //Rhino.UI.Panels.OpenPanel(type.GUID);
    Rhino.UI.Panels.OpenPanelAsSibling(type.GUID, PanelIds.Layers);
   
return Result.Success;
}

Here, we used another static field PanelIds.Layers, which refers to the Guid of the Layers panel, and indicating that we wish to dock our custom panel with the Layers panel.

image

That is it! Happy coding!

Advertisements
 
1 Comment

Posted by on June 12, 2014 in CAD, Dotnet/C#, General

 

Tags: , , , , , , , , , ,

One response to “Rhino C# Development (V) : Create and dock Rhino Panels side-by-side

  1. erdem

    November 20, 2014 at 2:27 am

    Hello, firstly thanks.
    i am getting this error
    Error 1 The type or namespace name ‘GeometryPanel’ could not be found (are you missing a using directive or an assembly reference?)

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: