Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Calling Program from inside a Program

#1
I feel like the answer to this question exists on this forum but just can't figure out the right search terms to find it.

I have a program that needs to call another program, but can't find the instruction within the program object to do this.  The RunProgram() function just runs the program itself rather than adding a subroutine call to the list of program instructions, which is what I'm trying to do.  I can figure out how to do all the other instructions except for the one that adds a program call.  

For example:

program = _rdk.AddProgram($@"LeaveHome");
                program.SetFrame(frame);
                program.SetTool(_rdk.GetItemByName("Tool 1"));
                program.MoveL(home_free);
                program.???? <--- need to add a program call here, using the name or id of an already existing program 
#2
Hi!
I guess what you are looking for is the RunInstruction() function, something like program.RunInstruction('programName', INSTRUCTION_CALL_PROGRAM) should do the job

Here's the link to the doc https://robodk.com/doc/en/PythonAPI/robo...nstruction
#3
That would be perfect, except I'm using the C# API and the RunInstruction() function does not appear to be available the way it is in the Python API. If it has a different name I sure can't find it.
#4
RunInstruction is the same as RunCodeCustom.

We just updated the official RoboDK API on GitHub to also include RunInstruction which is the official name.
#5
Thanks! Here's some example C# code if anyone needs this in the future. It would be ideal if the function names were the same across the various APIs though, I frequently look at Python example code since more of that exists than C#. The RunInstruction name is much more intuitive than RunCodeCustom.

IItem program = _rdk.AddProgram("FullCycle");
program.RunCodeCustom("LeaveHome", ProgramRunType.CallProgram );
foreach( string prog_name in prog_list )
{
program.RunCodeCustom( prog_name, ProgramRunType.CallProgram);
}
program.RunCodeCustom("ReturnHome", ProgramRunType.CallProgram);
#6
The naming of the functions should be uniform across all versions of the RoboDK API.

Let us know if you find inconsistencies or missing functions and we'll fix it with priority.
  




Users browsing this thread:
1 Guest(s)