RoboDK Forum
Import/Export Programs via 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: Import/Export Programs via API (/Thread-Import-Export-Programs-via-API)



Import/Export Programs via API-Leo-04-30-2020

Hello,

I'm using the C++ API to controll the RoboDK from an external application.
As an example, I used the c++ example from the gitlab projecthttps://github.com/RoboDK/RoboDK-API/.

I would have some question about the API because I was not able to solve this using the documentation.

- Is there a posibility to import/export programs (not as robot specific program) via the API?

- Who is it possible to get the values of non-movement instructions within a program ? (Item::Instruction(...) only returns types and positions but no values for speed- or wait-instructions)

- What shoud be inside the matrix of the Item::InstructionList(tMatrix2d m) method? (because it's everytime empty)

Attached you find a very small robodk project with one program inside which I want to export and later import via the API.

Thank you very much in advance for your help.


RE: Import/Export Programs via API-Albert-05-04-2020

Hi Leo,

If you want to generate a generic program you can use a neutral post processor such as the CSV post or a Gcode post. This will generate a generic program with all the information needed. We'll soon add a post that automatically creates a Python script that can be run in simulation.

You can change instruction parameters as shown in this example:
//www.sinclairbody.com/doc/en/PythonAPI/examples.html#modify-program-instructions

We just added support for this so make sure to upload RoboDK. Also, the Python API uses a dictionary to get/set values, with the C++ API you'll need to use a JSON string instead.

InstructionList is a bit outdated but should work. It will provide a large array describing the program as a 2D matrix.

Albert


RE: Import/Export Programs via API-Leo-05-13-2020

HiAlbert,

thank you for your response.

Exporting a program using the CSV Post Processor worked very well using the UI.
But is it possible to change the Post Processor using the C++ API?

I saw the python example:

Code:
robot = RDK.ItemUserPick("Select a robot", ITEM_TYPE_ROBOT)

# Set the robot post processor (name of the py file in the posts folder)
robot.setParam("PostProcessor", "Fanuc_RJ3")
But in C++, the RoboDK_API::Item has no setParam method.

Is it possible to later import the same file again?

Regarding get/set values using json string: do you have an example or documentation for that?

BR, Leo


RE: Import/Export Programs via API-Albert-05-13-2020

Hi Leo,

Yes, it is possible to change the post processor via the API. You'll find the setParam function for items available in the latest version of the C++ API on GitHub:
https://github.com/RoboDK/RoboDK-API/blob/master/C%2B%2B/Example/robodk_api.cpp

Importing program files such as LS files may work but you may loose information depending on the syntax you are using.

The example I provided includes an example using a dictionary in Python (it is automatically converted to a JSON string behind the scenes). You can do so in C++/Qt using a QJsonDocument.

Albert


RE: Import/Export Programs via API-Leo-05-26-2020

Hi Albert,

with the new update I'm now able to set the post processor for an item (program) using "item.setParam(...)".
Thank you.

But I can't find the regarding getting method to read the current selected post processor
-> there is no "item.getParam(...)" method defined.
Could you add this method to the C++ API?


Regarding importing a program:
I would use the same syntax as it exports using the CSV Post Processor.
Is there a method/way to import this file? Or is it only possilbe manually?

Could you provide a link to the example you mentioned (importing a program via python dictionary)?

BR,
Leo


RE: Import/Export Programs via API-Albert-05-27-2020

Hi Leo,

It is already possible to retrieve the current post processor.
Simply pass an empty string to the Post Processor parameter

Code:
post_selected = robot.setParam("PostProcessor")

@Phillipcreated a post processor that may help you (attached). This post will generate a Python program as if you created it using the RoboDK API. You can reload your original program in RoboDK or move your robot using drivers.

Albert


RE: Import/Export Programs via API-Leo-05-28-2020

Hi Albert,

thank you for your help so far.

Could you reattach the mentioned post processor from Phillip?
You last post has no attachments.

BR, Leo


RE: Import/Export Programs via API-Albert-05-28-2020

Hi Leo,

Sorry, I missed the attachment.

Albert