Set Selection Mode
This example shows you how to set the SelectionMode. The SelectionMode defines what kind of geometry you can select in the graphical view of your station. This example demonstrates Surface, Part, Mechanism and nothing (selection disabled), though there are some more options. See SelectionModes Enum for all options.
Create a new station with a robot, run the Add-In and choose which selection mode you want by clicking the buttons. Click on the robot to see the different selection modes.
Example
This example shows how to set the selection mode.
public void SetSelectionModeExample()
{
Project.UndoContext.BeginUndoStep("Set Selection Mode");
try
{
// Add a ToolWindow where we can put some buttons.
ToolWindow tw = new ToolWindow();
tw.Caption = "New ToolWindow";
// Add it docked to the right of the screen.
UIEnvironment.Windows.AddDocked(tw, DockStyle.Right);
// Create the buttons.
Button btn = new Button();
// Set the text of the button.
btn.Text = "Select surface";
// Set the size of the button.
btn.Size = new Size(190, 40);
// Set the location of the button (pixels from top left corner).
btn.Location = new Point(5, 5);
// Add an event handler to the button.
btn.Click += new EventHandler(btn1_clicked);
// Add the button to the ToolWindow.
tw.Control.Controls.Add(btn);
// Create a new button.
Button btn2 = new Button();
btn2.Text = "Select part";
btn2.Size = new Size(190, 40);
btn2.Location = new Point(5, 50);
btn2.Click += new EventHandler(btn2_clicked);
tw.Control.Controls.Add(btn2);
// And one more button.
Button btn3 = new Button();
btn3.Text = "Select mechanism";
btn3.Size = new Size(190, 40);
btn3.Location = new Point(5, 95);
btn3.Click += new EventHandler(btn3_clicked);
tw.Control.Controls.Add(btn3);
// And yet another button.
Button btn4 = new Button();
btn4.Text = "Select disabled";
btn4.Size = new Size(190, 40);
btn4.Location = new Point(5, 140);
btn4.Click += new EventHandler(btn4_clicked);
tw.Control.Controls.Add(btn4);
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
// The event handler for the first button.
static void btn1_clicked(object sender, EventArgs e)
{
// Call the method that sets the SelectionMode.
// See further down for this method.
SetSelectionMode(SelectionModes.Surface);
}
// The event handler for the second button.
static void btn2_clicked(object sender, EventArgs e)
{
// Call the method that sets the SelectionMode.
// See further down for this method.
SetSelectionMode(SelectionModes.Part);
}
// The event handler for the third button.
static void btn3_clicked(object sender, EventArgs e)
{
// Call the method that sets the SelectionMode.
// See further down for this method.
SetSelectionMode(SelectionModes.Mechanism);
}
// The event handler for the fourth button.
static void btn4_clicked(object sender, EventArgs e)
{
// Call the method that sets the SelectionMode.
// See further down for this method.
SetSelectionMode(SelectionModes.Disable);
}
// This method sets the selection level.
static void SetSelectionMode(SelectionModes mode)
{
// Go through all present windows.
foreach (Window w in UIEnvironment.Windows)
{
// If there is a DocumentWindow that contains a GraphicControl
if ((w is DocumentWindow) && (w.Control is GraphicControl))
{
// Set the SelectionMode.
GraphicControl gc = w.Control as GraphicControl;
if (gc != null)
gc.Picker.SelectionMode = mode;
}
}
}
Required Namespaces
ABB.Robotics.RobotStudio.Environment
ABB.Robotics.RobotStudio.Stations