Methods
This example shows you how to use some of the methods in the Body class. It creates a box, and two points. Then it tells you in the logger (the output window in RobotStudio) if the points are inside or outside the box. It also finds the closest Vertex from the box to point2. It ends with making a copy of the box, and removes the original box body.
Example
Project.UndoContext.BeginUndoStep("BodyMethods");
try
{
Station station = Station.ActiveStation;
// Create a part to contain the bodies.
Part p = new Part();
p.Name = "My_Part";
station.GraphicComponents.Add(p);
// Create a solid box.
Matrix4 matrix_origo = new Matrix4(new Vector3(Axis.X), 0.0);
Vector3 size = new Vector3(0.5, 0.5, 0.5);
Body box = Body.CreateSolidBox(matrix_origo, size);
box.Name = "Box";
p.Bodies.Add(box);
// Create two points.
Vector3 point1 = new Vector3(0.1, 0.1, 0.1);
Vector3 point2 = new Vector3(0.6, 0.6, 0.6);
// Test if the points are inside the box.
Logger.AddMessage(new LogMessage("Point one " + point1.ToString() + " is inside the box: " + box.IsPointInside(point1).ToString()));
Logger.AddMessage(new LogMessage("Point two " + point2.ToString() + " is inside the box: " + box.IsPointInside(point2).ToString()));
// Find the vertex closest to point2.
Vertex closestVert = box.FindClosestVertex(point2);
Logger.AddMessage(new LogMessage("The closest vertex to point2 is : (" + closestVert.Position.x.ToString() +
", " + closestVert.Position.y.ToString() +
", " + closestVert.Position.z.ToString() + ")"));
// Copy the box.
Body boxcopy = (Body)box.Copy();
boxcopy.Name = "Copy of " + box.Name;
p.Bodies.Add(boxcopy);
// Remove the original box body.
p.Bodies.Remove(box);
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
Required Namespaces
ABB.
ABB.