Last updated

Getting Started

Quick Tutorial

Get object type - right click context menu plugin

This simple plugin provides a way to fetch the type of a selected data object in the Petrel panes. This is very useful when developing plugins so you can find the matching data objects in Ocean to interact with in more complex plugins.

Create Ocean Plug-inCreate Ocean Plug-in

Open Visual Studio and create a new project

  1. Search for the Ocean Plug-in template

  2. Select Ocean Plug-in and click Next

    Create Ocean Plug-in
  3. Give your project a name and click Create

    Create Ocean Plug-in

The Ocean Project Wizard will pop up

  1. Give your plugin class a valid name

Recommend providing a unique class name as you may come back later and add more plugins to your solution. The other metadata can be modifed later on in the code.

  1. Check Create new module and Register modules in this solution

  2. Click Next

    Create Ocean Plug-in
  3. Ensure your new module is checked and click Next

    Create Ocean Plug-in
  4. Provide a unique name for the new module which will contain a new command handler for the code to be executed.

  5. Check New Command and provide a unique name for the command handler.

  6. Click Next

    Create Ocean Plug-in

In this step you need to register the command that will be executed when you click on Get Object Type in the context menu

  1. Click on the Add new command button to insert a new command under the Commands item.

  2. Select the command and update the Id to an appropriate name.

  3. Update the Caption so it is more descriptive of the action it will perform, this will be the text shown in the context menu.

  4. Click Next

    Create Ocean Plug-in
  5. Click Finish

    Create Ocean Plug-in

Visual Studio Project

Once your project is created, the Solution Explorer should look something like this:

Create Ocean Plug-in
  1. Open the Module class and under the IntegratePresentation method, register the context menu item like so:

    SimpleCommandContextMenuHandler<object> otHandler = new SimpleCommandContextMenuHandler<object>(new CommandItem(ObjectTypeCommandHandler.ID));
    PetrelSystem.ToolService.AddCommandContextMenuHandler(otHandler);
    Create Ocean Plug-in
  2. Open the CommandHandler class and implement the logic that will run when the user clicks on the Get Object Type item in the context menu.

    This will loop through the selected objects in the data trees and print the type to the message log in Petrel.

    foreach (object obj in context.GetSelectedObjects<object>())
    {
        PetrelLogger.InfoOutputWindow("Object type: " + obj.GetType().ToString());
    }
    Create Ocean Plug-in
  3. Then you can build the project, and if all goes well the plugin will be created and added to Petrel automatically.

  4. Launch Petrel and test the plugin

You have successfully created your first plugin!