RoboDK Forum
Attach an object in python- 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: Attach an object in python (/Thread-Attach-an-object-in-python)



Attach an object in python-artik00-03-08-2022

Hello,

How to write code correctly in python so that it attaches an object?


I added attach condition to my python code, but after running this code "main program" is created and gripper doesnt attach the object.


Hope you understand what i mean

Thank you.


RE: Attach an object in python-Albert-03-09-2022

I understand you want to add an instruction to your program to attach an object to the gripper, correct?

The line you highlighted will attach the object to the gripper right the same moment you call that instruction (it does not add it to the program).

The following example will help you add the attach event instruction to your program:
Code:
RDK = Robolink()

prog = RDK.AddProgram("test1")
target = RDK.Item("Target")
tool = RDK.Item("Gripper")
framepallet = RDK.Item("Pallet")

prog.MoveL(target)

INS_TYPE_EVENT = 7
EVENT_ATTACH = 0
EVENT_DETACH = 1

ins_event_attach = {'Type': INS_TYPE_EVENT, 'Behavior': EVENT_ATTACH, 'ToolPtr': str(tool.item)}
ins_event_detach = {'Type': INS_TYPE_EVENT, 'Behavior': EVENT_DETACH, 'ToolPtr': str(tool.item), 'FramePtr': str(framepallet.item)}
prog.setParam("Add",ins_event_attach)
prog.setParam("Add",ins_event_detach)

You can find a similar example here:
//www.sinclairbody.com/doc/en/PythonAPI/examples.html#modify-program-instructions


RE: Attach an object in python-SamuelEStreamline-01-31-2023

Is there a way to add an instruction to attach a specific RoboDK item (3D object) by name to the event attach dictionary?

For example:
Code:
tube_1 = RDK.Item('Tube_1', ITEM_TYPE_OBJECT)

ins_event_attach = {'Type': INS_TYPE_EVENT, 'Behavior': EVENT_ATTACH, 'ToolPtr': str(tool.item),
'Object': tube_1}


My current issue is that I need to attach several 3D objects to the robot tool but only the closest object will attach.

Thank you.


RE: Attach an object in python-Albert-02-01-2023

This is currently not possible using an instruction but you can trigger a program call to a Python script that will change the parent an object is attached to.


RE: Attach an object in python-SamuelEStreamline-03-30-2023

Hi Albert,

I'm encountering an issue where my program event attach instruction is attaching the incorrect object. Object B is closer to the tool tcp, but I actually want to attach Object A. We have quite a few objects clustered together and I need to be able to specify the exact object I want to attach.

This first image shows the Event Instruction created from the API. The second image shows the Event Instruction that I want to be able to create from the API. Do you have any solutions?