Transforming Path
This tutorial describes how to transform targets referenced by RsMoveInstructions.
You will need an RsMoveInstructions in the active path procedure to run this tutorial.
This example uses the method GetTargetsfromPath, described in Getting Targets from a Path.
Solution
Create variables of Vector3 type to store the user defined translation and orientation values.
// Define the values for the transformation matrix, which will be applied to the path Vector3 newTranslation = new Vector3(0.500, 0.500, 0); Vector3 newOrientation = new Vector3(Globals.DegToRad(0), Globals.DegToRad(0), Globals.DegToRad(45)); Matrix4 newMatrix = new Matrix4(newTranslation, newOrientation);Get list of RsTarget objects from the path using Getting Targets from a Path.
// Get all the targets from RsPathProcedure object List<RsTarget> targets = GetTargetsfromPath(pathProcedure);Apply the new matrix transformation relative to each target's global matrix using SetRelativeTransform(Matrix4, Matrix4).
// Apply the new transformation matrix to each target relative to its global matrix foreach (RsTarget target in targets) { target.Transform.SetRelativeTransform(target.Transform.GlobalMatrix, newMatrix); }
Example
This example shows how to apply a transformation to targets associated with an RsMoveInstruction object.
private static void TransformPath(RsPathProcedure pathProcedure)
{
// Begin UndoStep
Project.UndoContext.BeginUndoStep("Transform Path");
try
{
// Define the values for the transformation matrix, which will be applied to the path
Vector3 newTranslation = new Vector3(0.500, 0.500, 0);
Vector3 newOrientation = new Vector3(Globals.DegToRad(0),
Globals.DegToRad(0),
Globals.DegToRad(45));
Matrix4 newMatrix = new Matrix4(newTranslation, newOrientation);
// Get all the targets from RsPathProcedure object
List<RsTarget> targets = GetTargetsfromPath(pathProcedure);
// Apply the new transformation matrix to each target relative to its global matrix
foreach (RsTarget target in targets)
{
target.Transform.SetRelativeTransform(target.Transform.GlobalMatrix, newMatrix);
}
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
Required Namespaces
ABB.Robotics.RobotStudio.Stations