RoboDK Forum
Add first line to program using 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 first line to program using API (/Thread-Add-first-line-to-program-using-API)



Add first line to program using API-Bradhoffm-05-09-2022

Hello,

I am using the commands "InstructionSelect" and "RunInstruction" to modify robot programs with the RoboDK API. I have found that it is possible to add lines to any location in the program, except for the first instruction. Is it possible to add the first instruction of the program?


RE: Add first line to program using API-Sam-05-12-2022

Hi,

Here's how to reorder Program Instructions, which should allow you to insert an instruction as a first instruction.

Code:
# Example to reorder instructions
# Test with Example-01.a

from robolink import *

RDK = Robolink()

p1 = RDK.Item("ApproachMove", ITEM_TYPE_PROGRAM)
p2 = RDK.Item("PaintTop", ITEM_TYPE_PROGRAM)

program_from = p1
program_to = p1 # this can be a different program as well
instruction_id_from = 2
instruction_id_to = 0

# Choose if you want to reorder before or after
reorder_cmd = "ReorderBefore"
#reorder_cmd = "ReorderAfter"

# Warning: This can crash if id's are not valid
program_from。setParam (reorder_cmd str(指令_id_from) + "|" + str(instruction_id_to) + "|" + str(program_to.item))



RE: Add first line to program using API-Bradhoffm-05-13-2022

Hi Sam,

The sample code worked well. Thanks!