Creating a New View
This example opens up a new graphical view of our station.
This can be good if you want to see your station from different views at once. You can arrange the views horizontaly or verticaly. If you want to follow a specific object in the new window, you can add the FollowObject property. See the Camera class for more examples on how to use the camera.
Solution
- Begin by creating a GraphicControl instance. Set the station as the root object. The graphic control acts as the canvas where your station will be visually represented.
GraphicControl gc = new GraphicControl(); gc.RootObject = Station.ActiveStation; - Create a Camera. The camera's role is to define the point of view from which the station is observed. By adjusting the LookFrom property, you can pinpoint the exact perspective you wish to achieve.
Camera cam = new Camera(); cam.LookFrom = new Vector3(10, 10, 10); gc.Camera = cam; - To show your new graphical view, put the GraphicControl inside a DocumentWindow.
DocumentWindow dw = new DocumentWindow("Window ID", gc, "Window Caption"); UIEnvironment.Windows.Add(dw);
Example
Project.UndoContext.BeginUndoStep("AddNewView");
try
{
// Create a new graphic control.
GraphicControl gc = new GraphicControl();
// Set our station as the object for the graphic control.
gc.RootObject = Station.ActiveStation;
// Create a camera (our view at the station).
Camera cam = new Camera();
// Tell it where to look from.
cam.LookFrom = new Vector3(10, 10, 10);
// Set the camera as the graphic control's camera.
gc.Camera = cam;
// Create a new window, with our graphic control.
DocumentWindow dw = new DocumentWindow("Window ID", gc, "Window Caption");
// Add the window to RobotStudio.
UIEnvironment.Windows.Add(dw);
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}