43.1.8. Register Ribbon Icon using ProcessNet Python

../_images/image66.png

Figure 43.12 User Icon on Ribbon

The user can customize the ribbon layout and register ProcessNet script.

Following things are supported:

  • Creation ribbon tab

  • Creation ribbon group

  • Creation ribbon icon

  • Register the ProcessNet script to the icon

Creation custom group and icon

The user can create ribbon group and icon.

  • Casting the ribbon Manager interface: ribbonManager = application.RibbonManager

  • Find the ribbon tab “Customize”: ribbonTab = ribbonManager.FindRibbonTab(“Customize”)

  • Create the ribbon Group: ribbonGroup = ribbonTab.AddRibbonGroup(“PNet Example”)

  • Create the ribbon icon : menuControl = ribbonGroup.AddMenuControl(MenuControlType.MenuControlType_Button, 8001)

Register ProcessNet function to ribbon icon

The user can register ProcessNet function to ribbon icon.

  • Set using ProcessNet function: IMenuControl.UseProcessNetFunction = True

  • Set the ProcessNet dll path: IMenuControl.ProcessNetScriptPath = ProcessNetScriptPath

  • Set the ProcessNet type : IMenuControl.ProcessNetType = ProcessNetType. ProcessNetType_Python

Sample Code

def register_function():
   ribbonManager = application.RibbonManager
   ribbonTab = ribbonManager.FindRibbonTab("Customize")
   ribbonGroup = ribbonTab.AddRibbonGroup("PNet Example")

   menuControl = ribbonGroup.AddMenuControl(MenuControlType.MenuControlType_Button, 8011)
   menuControl.ProcessNetType = ProcessNetType.ProcessNetType_Python
   menuControl.Caption = "MyTooltip"
   menuControl.Tooltip = "PNet Example"
   menuControl.UseProcessNetFunction = True
   menuControl.UseBigIcon = True

   menuControl.SetIconFromFile("C:\\Examples\\example.ico", 16, 16) # Icon File Path
   menuControl.ProcessNetScriptPath = "C:\\Examples\\CreateBody.py" # Python Script Path

initialize()
register_function()
dispose