Results 1 to 7 of 7

Thread: Programming using the Robot API

  1. #1
    Member
    Join Date
    2009-10
    Posts
    28
    0 Did you find this post helpful? Yes

    Default Programming using the Robot API

    I've recently started coding using the Robot API.

    Using the .com interface in combination with a external windowsform application. Everything works fine. The standard SDK has enough information to get you going.

    However I want to make a .dll class with forms as a robot addin. However I haven't found any information on how to get the thing working. Anyone have any ideas?

  2. #2
    Member
    Join Date
    2009-10
    Posts
    15
    0 Did you find this post helpful? Yes

    Default Re: Programming using the Robot API

    Your dll needs to be a COM server with at least one COM class that implements IRobotAddIn interface.
    Then you can use Tools\Add-ins\Add/Delete menu option to install your add-in in Robot menu.

  3. #3
    Member
    Join Date
    2009-10
    Posts
    28
    0 Did you find this post helpful? Yes

    Default Re: Programming using the Robot API

    Thank you for the reply,

    It got the com server to work. (At least I think it does).
    It is addable as Reference in Visual Studio.
    The dll is still not seen by the addin manager.
    All I want to do first is to get a Messagebox saying Hello world.
    Here is the code I came up with:

    ==============================================================

    using System;
    using RobotOM;
    using System.Windows.Forms;

    //References used:
    //http://blog.stevedoria.net/20051008/creating-com-components-using-visual-csharp-dot-net


    namespace Helloworld
    {
    // public interface IRobotAddIn;
    //Definition of the Robot program extension.
    //This interface must implement each component that is integrated
    //with the Robot program and that extends its functionality

    public class Helloworld : IRobotAddIn
    {
    public IRobotCmdInfo robcmdinfo;
    public int _add_in_id;
    public RobotApplication robapp;
    public RobotCmdList _cmd_list;
    public IRobotAddInMngr AddInMngr = default(IRobotAddInMngr);
    public IRobotAddInRegistrar REG = default(IRobotAddInRegistrar);

    //command list
    public void commandlist()
    {
    long num = _cmd_list.New(1, "Hello World");
    robcmdinfo = _cmd_list.Get((int)num);
    robcmdinfo.MenuEnabled = true;
    robcmdinfo.Id = 1;
    robcmdinfo.Name = "Hello World";
    }

    //general dll data for registry
    public void programdata()
    {
    REG.Guid = "684044bd-a077-408c-9a00-e2648c36397f";
    //GUID identifier of the main extension component (presented interchangeably with Progld)
    REG.ProductName = "Hello World";
    //Extension name
    REG.ProgId = "Helloworld";
    //Identifier of the main extension component (presented interchangeably with Guid)
    REG.ProviderName = "n/a";
    //Name of the extension supplier
    REG.InstallMenu("Hello World", _cmd_list);
    //Function adds menu with the specified name to all Robot program views.
    //The commands specified in the list will are the menu options.
    //They will be supported by the extension whose Progld or Guid have been set earlier.
    //If identifier of the extension supporting commands from the list is not specified,
    //the function returns zero value (False).
    }

    public bool Connect(RobotApplication robot_app,int add_in_id, bool first_time)
    //Function wil be called up by the Robot application when the extension is connected to the program:
    //for the first time - upon user's request or during first activation of the program after installing the extension;
    //for the next time - while activating the Robot program again.
    //The extension should remember the access interface to the Robot application
    //(RobotApplication) so that the extension can use its functionality. The extension, while being connected,
    //is ascribed its identifier which should be remembered since it will be needed during subsequent communication
    //with the Robot program. While connecting the extension to the application for the first time it is possible
    //to perform additional initializing operations. If all is performed correctly,
    //then function should return a value different from zero (True).

    {
    try
    {
    robapp = robot_app;
    _add_in_id = add_in_id;
    commandlist();

    if (first_time == true)
    {
    programdata();
    REG.Register();
    // Function saves information about the extension to the register.
    //If registration is performed successfully,
    //a value different from zero is returned (True).
    //Registration failure may result from lack of settings concerning suppler name
    //or product as well as identifier (Guid or Progld).
    }
    return true;
    }
    catch {
    return false;
    }

    }

    public bool Disconnect()
    //This function will be called up before the extension is disconnected with the Robot program
    //(e.g. while exiting the application or upon user's request who wants no longer to use the extension).
    // If there is any reason for the extension not to be disconnected with the program at the given moment,
    //the function should return zero value (False).
    {
    programdata();
    //REG.Unregister();
    //Function deletes information about the extension from the register.
    return false;
    }

    public void DoCommand(int cmd_id)
    //Function will be called up by the Robot program if a user selects the menu option linked with the
    //command supported by this extension.
    {
    if (cmd_id == 1) MessageBox.Show("Hello World");
    }

    public double GetExpectedVersion()
    // Function should return the number of the RobotOS model version which is used by the extension.
    //It will enable warning a user in a situation when the extension that is being installed by the
    //user expects a newer Robot program version than the one currently used by the user. .
    {
    return 9.5; //RSA 2009
    }

    public int InstallCommands(RobotCmdList cmd_list)
    //Function will be called up by the application to obtain information about the commands that are made
    //available by the extension. List specified by the parameter should be filled out with the information
    //about all the commands defined by the extension. If the operation is performed successfully,
    //the function should return a value different from zero (True).
    {
    try
    {
    for (int i = 1; i <= cmd_list.Count; i++)
    {
    AddInMngr.InstallCommand(_add_in_id, i);
    //Add-ins Manager keeps tracks to all add-ins currently registered in Robot.
    }
    return 1;
    }
    catch
    {
    return 0;
    }


    }
    }

    }

  4. #4
    Member
    Join Date
    2009-10
    Posts
    15
    0 Did you find this post helpful? Yes

    Default Re: Programming using the Robot API

    If your assembly is COM-visible, all you need is to embed the type library in your dll.

    You can do it as follows:
    1. Generate tlb for your assembly (go to Properties, Build tab, check 'Register for COM interop', save project and rebuild)

    2. Add tlb to final dll (open your dll in VS, select 'Add Resource' from context menu, choose 'Import...', point the tlb file, as resource type set TYPELIB, modify Resource identifier to 1, save dll file)

    You can use OLE viewer to verify that the tlb is embeded in dll.

    Now you should be able to add the dll in Robot Tools/Add-Ins/Add/Delete menu.

  5. #5
    Member
    Join Date
    2009-10
    Posts
    15
    0 Did you find this post helpful? Yes

    Default Re: Programming using the Robot API

    Apart from embedding the type library in your add-in dll you also have to change the add-in implementation a bit.
    I'm sorry I did not look at it closer before.

    Let me order the stuff connected to Robot add-ins API.

    IRobotAddIn interface is used to communicate between Robot and your add-in object.
    IRobotAddInRegistrar is to be used by the installer of your add-in, not by the add-in itself.
    For the present you don't need to use IRobotAddInMngr interface at all - it may be useful in the future.

    Let's look at methods of IRobotAddIn interface.

    public bool Connect(RobotApplication robot_app, int add_in_id, bool first_time)

    You need to store the robot_app reference to Robot Application object.
    If your add-in needs some extra initialization before it can be used you can check the flag first_time and if it is true this is a good moment for such an initialization.

    public bool Disconnect()

    You should release the reference to Robot Application.

    public int InstallCommands(RobotCmdList cmd_list)

    You must fill the cmd_list object with all commands supported by your add-in. Use cmd_list.New() method here.
    These commands will be presented to the user when he adds your add-in using Robot GUI.

    public void DoCommand(int cmd_id)

    You must process given command. The cmd_id is one of identifiers you add to cmd_list inside InstallCommands() method.

    The sample implementation of your add-in can look as follows:

    namespace AddInCs
    {
    public class MyAddIn : IRobotAddIn
    {
    private RobotApplication robapp;
    private int _add_in_id;

    public bool Connect(RobotApplication robot_app, int add_in_id, bool first_time)
    {
    try
    {
    robapp = robot_app;
    _add_in_id = add_in_id;
    return true;
    }
    catch
    {
    return false;
    }

    }

    public bool Disconnect()
    {
    return true;
    }

    public int InstallCommands(RobotCmdList cmd_list)
    {
    try
    {
    cmd_list.New(1, "Hello World");
    return 1;
    }
    catch
    {
    return 0;
    }
    }

    public void DoCommand(int cmd_id)
    {
    if (cmd_id == 1)
    {
    MessageBox.Show("Hello World");
    }
    }

    public double GetExpectedVersion()
    {
    return 9.5; //RSA 2009
    }

    }
    }

    That's all. You can add the option 'Hello World' to Robot menu using Tools/Add-Ins/Add/Delete.

    You can also use RobotAddInRegistrar in your installer to have your add-in options added to Robot menu automatically.
    All that RobotAddInRegistrar does is creating some entries in Windows registry that are read by Robot on startup when it builds the menu.

  6. #6
    Member
    Join Date
    2009-11
    Posts
    2
    0 Did you find this post helpful? Yes

    Default Re: Programming using the Robot API

    this discussion is what i was looking for.

    But i don't understand what you meant in your previous post. After i check 'register for COM object' in VS, than it sais doesn't contain any types that can be registered for COM Interop.

    Can you kindly explain step by step?

    Many Thanks.

  7. #7
    Woo! Hoo! my 1st post
    Join Date
    2011-06
    Posts
    1
    0 Did you find this post helpful? Yes

    Default Re: Programming using the Robot API

    Thank you Marek for these detailes.
    Now my aplication works perfect as dll, but...
    ONLY on my computer.
    I can add it to addins on any other one but it remains inactive and no command menu appears.
    I've been trying to copy all registered data and references but it didn't help too.
    Perhaps I need to implement the IRobotAddInRegistrar or create some extra setup files. Or maybe I'm just missing somethig stupid. Please help. I'm working on it for two weeks already.

Similar Threads

  1. Programming in Revit
    By rinu.bs in forum Revit - API
    Replies: 2
    Last Post: 2010-10-14, 09:47 PM
  2. API programming
    By Rwss in forum Robot Structural Analysis
    Replies: 1
    Last Post: 2009-09-25, 06:36 AM
  3. Key Programming
    By MARPOW in forum AutoLISP
    Replies: 1
    Last Post: 2007-11-05, 11:28 AM
  4. C# programming examples
    By cyr_j in forum Dot Net API
    Replies: 3
    Last Post: 2006-06-08, 06:06 PM
  5. Programming with .NET
    By dorisgin in forum ATP Course Wishlist
    Replies: 1
    Last Post: 2006-02-15, 06:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •