RoboDK Forum
Add Instructions to Program in C# API- Printable Version

+- RoboDK Forum (//www.sinclairbody.com/forum)
+-- Forum: RoboDK (EN) (//www.sinclairbody.com/forum/Forum-RoboDK-EN)
+--- Forum: RoboDK API (//www.sinclairbody.com/forum/Forum-RoboDK-API)
+--- Thread: Add Instructions to Program in C# API (/Thread-Add-Instructions-to-Program-in-C-API)



Add Instructions to Program in C# API-joebgold-07-08-2022

I am looking to modify an existing program in RoboDK through the use of the C# RoboDK API. I have found that I can get the list of instructions with the InstructionList function call (though the Instruction types do not seem to line up to the INS_TYPE_* definitions). I am looking to add a new instruction at some position in the program and, while there appears to be a method for setting a movement instruction, the API seems incomplete as to adding other types of instructions. My first objective would be to add a set speed command to change the speed of the program however this does not seem to be available. setInstruction only seems to allow parameters for movement commands. Can you provide insight into how to insert other commands to an existing program through the API (for example, a speed change half way through the program)?


public void setInstruction(int ins_id, string name, int instype, int movetype, bool isjointtarget, Mat target, double[] joints)
{
link._check_connection();
link._send_Line("Prog_SIns");
link._send_Item(this);
link._send_Int(ins_id);
link._send_Line(name);
link._send_Int(instype);
if (instype == INS_TYPE_MOVE)
{
link._send_Int(movetype);
link._send_Int(isjointtarget ? 1 : 0);
link._send_Pose(target);
link._send_Array(joints);
}
link._check_status();
}


RE: Add Instructions to Program in C# API-Albert-07-12-2022

If you simply need to change the speed you could use the setSpeed function:
Code:
...
program.MoveJ(...)
...
program.setSpeed(new_speed)
...

You can also use setParam to get or set instruction data. This method requires manipulating JSON strings. This example shows the concept:
//www.sinclairbody.com/doc/en/PythonAPI/examples.html#modify-program-instructions
If you set the instruction id to -1 or you index passed the last instruction it will add the instruction as a new instruction (instead of modifying an existing instruction). You can also reorder instructions if you need. This example shows the concept:
C:\RoboDK\Library\Macros\Reorganise_Prog.py