Click or drag to resize

Modifying modules and programs

Overview

Using the Task object it is possible to load and save programs and individual modules. You can also unload programs, get the position of the motion pointer (MP) and the program pointer (PP) as well as modify a robot position.

Load modules and programs

To load a module or program file you need the path to the file in the file system of the controller. When the file is loaded into memory the RapidLoadMode enumeration argument, Add or Replace, specifies whether or not it should replace old modules or programs.

If the file extension is not a valid module (mod or sys) or program (pgf) extension an ArgumentException is thrown.

C#
try

{

aTask.LoadProgramFromFile(aPrgFileName, RapidLoadMode.Replace);

aTask.LoadModuleFromFile(aModFileName, RapidLoadMode.Add);

}

catch (ArgumentException ex)

{

return;

}
VB
Try

ATask.LoadProgramFromFile(APrgFileName, RapidLoadMode.Replace)

ATask.LoadModuleFromFile(AModFileName, RapidLoadMode.Add)

Catch ex As ArgumentException

Return

End Try
Save and unload RAPID program

You can save a program using the SaveProgramToFile method and unload it using the DeleteProgram method. These methods save and unload all modules in the task.

C#
Task[] taskCol = aController.Rapid.GetTasks();

foreach (Task aTask in taskCol)

{

aTask.PrograamName = aTask.Name;

aTask.SaveProgramToFile(saveDir);

aTask.DeleteProgram();

}
VB
Dim TaskCol As Task() = AController.Rapid.GetTasks()

Dim AnObject As Object

For Each AnObject in TaskCol

ATask = DirectCast(AnObject, Task)

ATask.ProgramName = ATask.Name

ATask.SaveProgramToFile(SaveDir)

ATask.DeleteProgram()

Next
Save module

You can save a module by using the Module.SaveToFile method. As argument you use a path to the controller file system.

C#
aModule.SaveToFile(aFilePath);
VB
AModule.SaveToFile(AFilePath)
ProgramPointer and MotionPointer

The Task.ProgramPointer property returns the current location of the program pointer (module, routine and row number), that is, where the program is currently executing. The same functionality is available for motion pointer by using the MotionPointer property.

C#
ProgramPointer pp = aTask.ProgramPointer;

if (pp != ProgramPointer.Empty)

{

int aStartRow = pp.Start.Row;

.....

}
VB
Dim APP As ProgramPointer = ATask.ProgramPointer

If Not APP = ProgramPointer.Empty Then

Dim AStartRow As Integer = APP.Start.Row

.....
ModifyPosition method

Using the ModifyPosition method of the Task object you can modify the position of a RobTarget instance in the currently loaded program. As arguments you supply a module Name as well as a TextRange object. The first RobTarget within the text range specified by the TextRange object will be changed using the current TCP of the active mechanical unit.

C#
this.ATask.ModifyPosition(aModule, aTextRange)
VB
Me.ATask.ModifyPosition(AModule, ATextRange)
Tip Tip
For more information on Task methods and properties, see in the Reference Manual FlexPendant SDK.