Class RsTargetCollection
A collection of RsTargets.
Inheritance
RsTargetCollection
Assembly: ABB.Robotics.RobotStudio.Stations.dll
Syntax
public class RsTargetCollection : ICollection, IEnumerable<RsTarget>, IEnumerable
Examples
Target Collection.
Project.UndoContext.BeginUndoStep("Copy Target");
try
{
// Instance active station.
Station stn = Station.ActiveStation;
// Get the active workobject.
RsWorkObject wobj = stn.ActiveTask.ActiveWorkObject;
// Create a new RobTarget and add it to the ActiveTask.
RsRobTarget robTarget = new RsRobTarget();
robTarget.Name = stn.ActiveTask.GetValidRapidName("MyTarget", "_", 10);
stn.ActiveTask.DataDeclarations.Add(robTarget);
// Create an RsTarget from wobj and RobTarget.
RsTarget target = new RsTarget(wobj, robTarget);
// Set the name of the target.
target.Name = robTarget.Name;
// Add RsTarget to ActiveTask.
stn.ActiveTask.Targets.Add(target);
// Copy the target.
RsTarget targetCopy = (RsTarget)target.Copy();
// Set the new name to the copied targets.
targetCopy.Name = target.Name + "_Copy";
// Add the copied target, after the original target, to the ActiveTask.
stn.ActiveTask.Targets.Add(targetCopy, target);
// Move the new target 0.5 meters along the X-axis.
targetCopy.Transform.X = targetCopy.Transform.X + 0.5;
// Set the highlight color of the target.
target.Highlight(Color.Green);
// Reset the highlight color of the target copy.
targetCopy.ResetHighlight();
// Remove the original target.
stn.ActiveTask.Targets.Remove(target);
}
catch (Exception)
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
Properties
Count
Declaration
public virtual int Count { get; }
Property Value
IsSynchronized
Declaration
public virtual bool IsSynchronized { get; }
Property Value
Item[Int32]
Declaration
public RsTarget this[int index] { get; }
Parameters
Type |
Name |
Description |
Int32 |
index |
|
Property Value
Parent
Declaration
public ProjectObject Parent { get; }
Property Value
SyncRoot
Declaration
public virtual object SyncRoot { get; }
Property Value
Methods
Add(RsTarget)
Declaration
public void Add(RsTarget target)
Parameters
Type |
Name |
Description |
RsTarget |
target |
The target to be added.
|
Examples
Add a target to a task.
Project.UndoContext.BeginUndoStep("Create Target");
try
{
// Instance active station.
Station stn = Station.ActiveStation;
// Get the active workobject.
RsWorkObject wobj = stn.ActiveTask.ActiveWorkObject;
// Create a new RsRobTarget and add it to ActiveTask.
RsRobTarget robTarget = new RsRobTarget();
robTarget.Name = stn.ActiveTask.GetValidRapidName("MyRobTarget", "_", 10);
stn.ActiveTask.DataDeclarations.Add(robTarget);
// Create an RsTarget from wobj and RobTarget.
RsTarget target = new RsTarget(wobj, robTarget);
target.Name = robTarget.Name;
// Add RsTarget to ActiveTask.
stn.ActiveTask.Targets.Add(target);
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
Exceptions
Add(RsTarget, RsTarget)
Declaration
public void Add(RsTarget target, RsTarget afterThisTarget)
Parameters
Type |
Name |
Description |
RsTarget |
target |
The target to be added.
|
RsTarget |
afterThisTarget |
The afterThisTarget that target should be added after.
If this null, target is added before the first target.
|
Exceptions
Contains(RsTarget)
Declaration
public bool Contains(RsTarget obj)
Parameters
Returns
CopyTo(RsTarget[], Int32)
Declaration
public void CopyTo(RsTarget[] array, int index)
Parameters
CopyTo(Array, Int32)
Declaration
public virtual void CopyTo(Array array, int index)
Parameters
GetEnumerator()
Declaration
public virtual IEnumerator GetEnumerator()
Returns
Remove(RsTarget)
Removes a target to from a task.
Declaration
public void Remove(RsTarget target)
Parameters
Type |
Name |
Description |
RsTarget |
target |
The target to be removed.
|
Examples
Remove a target to a task.
Project.UndoContext.BeginUndoStep("Target Properties");
try
{
// Instance active station.
Station stn = Station.ActiveStation;
// Get the active workobject.
RsWorkObject wobj = stn.ActiveTask.ActiveWorkObject;
// Create a new RsRobTarget and add it to ActiveTask.
RsRobTarget robTarget = new RsRobTarget();
robTarget.Name = stn.ActiveTask.GetValidRapidName("MyRobTarget", "_", 10);
stn.ActiveTask.DataDeclarations.Add(robTarget);
// Create an RsTarget from wobj and RobTarget.
RsTarget target = new RsTarget(wobj, robTarget);
// Add RsTarget to ActiveTask.
stn.ActiveTask.Targets.Add(target);
// Set the name of the target.
target.Name = robTarget.Name;
// Add a custom attribute to the target.
target.Attributes.Add("MyAttribute", "10");
// Output the project that the target is part of, and the parent of the target.
Logger.AddMessage(new LogMessage("The target: " + target.Name + " is part of the project: " +
target.ContainingProject.Name + ". The targets parent is: " + target.Parent.Name));
// Output the ToString-reprentation of the target and its types diplay name.
Logger.AddMessage(new LogMessage("The targets ToString representation is '" +
target.ToString() + "' and its TypeDisplayName is '" + target.TypeDisplayName + "'."));
// Set the workobject of the target as the active workobject.
stn.ActiveTask.ActiveWorkObject = target.WorkObject;
// Create a copy of the RobTarget.
RsRobTarget newRobTarget = (RsRobTarget)robTarget.Copy();
// Assign the copy to the target.
target.RobTarget = newRobTarget;
// Check if the target is invisible, and make it visible and yellow.
if (!target.Visible)
{
target.Visible = true;
Color col = Color.Yellow;
target.Color = col;
}
// Make the target's grapical display size twice as large.
target.FrameSize = target.FrameSize * 2;
// Get the transform and output its values using the logger.
Logger.AddMessage(new LogMessage("Transform of target: " + target.Name
+ "; X: " + target.Transform.X
+ "; Y: " + target.Transform.Y
+ "; Z: " + target.Transform.Z
+ "; Rx: " + target.Transform.RX
+ "; Ry: " + target.Transform.RY
+ "; Rz: " + target.Transform.RZ
));
// Get the ReferenceFrame of the target.
Transform refFrame = target.ReferenceFrame;
// Show the reference frame in the graphics.
target.ShowReferenceFrame = true;
// If the AxisDirection of the target is undefined then set it to negative x.
if (target.ApproachVector == AxisDirection.Undefined)
{
target.ApproachVector = AxisDirection.NegativeX;
}
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
Exceptions
ToArray()
Declaration
public RsTarget[] ToArray()
Returns