How to start the a Robot Structural application through API

How to start the a Robot Structural application through API

HadiMoosavi
Enthusiast Enthusiast
2,294 Views
16 Replies
Message 1 of 17

How to start the a Robot Structural application through API

HadiMoosavi
Enthusiast
Enthusiast

Hi Everyone,

How do we code for starting the application? Apologies if this is a very simple question.

0 Likes
Accepted solutions (1)
2,295 Views
16 Replies
Replies (16)
Message 2 of 17

chjpcoi
Advocate
Advocate

Hi @HadiMoosavi 

You can access the link below, which has examples and basic steps for beginners

Link: https://forums.autodesk.com/t5/robot-structural-analysis-forum/api-tutorial/td-p/3939601 

Have a nice day

Message 3 of 17

HadiMoosavi
Enthusiast
Enthusiast
Will do. Thanks.
0 Likes
Message 4 of 17

HadiMoosavi
Enthusiast
Enthusiast

@chjpcoi , Hello again,

 

I looked at those locations. But I didn't find an example that launches Robot.

I found an article in Robot API tutorial (see below). But it does not seem to be the right code for launching a new instance of Robot. Could you please advise on this? By the way, I use C#.

HadiMoosavi_4-1659124589597.png

 

0 Likes
Message 5 of 17

Stephane.kapetanovic
Mentor
Mentor
Accepted solution

hi @HadiMoosavi 

To use API

using RobotOM;

// To use API with Robot and a project open 
IRobotApplication RobApp = new RobotApplication();
bool Visible = RobApp.Visible == -1,
     IsActive = RobApp.Project.IsActive == -1,
     Ready = Visible && IsActive;
if (Ready){ 
 // do something 
}
RobApp = null;

// To open Robot and create a new project 
RobotApplication RobApp = new RobotApplication();
RobApp.Visible = -1;
RobApp.Project.New(IRobotProjectType.I_PT_FRAME_3D);

Best regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
Message 6 of 17

HadiMoosavi
Enthusiast
Enthusiast

Thank you very much, Stephane.
What do Visible and Active properties are used for?
There is little information in the SDK.

0 Likes
Message 7 of 17

Stephane.kapetanovic
Mentor
Mentor

First state : instance created but robot not showed
Visible: Second state = App displayed to the user.
Project.IsActive: Third state = Project started

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
Message 8 of 17

HadiMoosavi
Enthusiast
Enthusiast

@Stephane.kapetanovic 
 I have another question if you would help.
Manually, I can open two instances of Robot.
Is it possible to open two instances using API?

0 Likes
Message 9 of 17

Stephane.kapetanovic
Mentor
Mentor

hi @HadiMoosavi 

I'm not sure I understand precisely, could you detail the reasons for such a request?
If you plan to use two successive function calls (cascade) on same thread, yes it is possible.
At the same time or very close on same server (multithread), it is not safe.
Working on two robot instances at the same time by API is not possible.

Best regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
Message 10 of 17

HadiMoosavi
Enthusiast
Enthusiast

@Stephane.kapetanovic 

I am glad you asked. Here it goes. 
I am trying to call RSA from Revit Dynamo in a Generative Design(GD) graph. GD which is some kind of evolutionary algorithm, runs six parallel instances of the graph which means six RSA instances. But based on your answer, it seems it is not possible. Do you have any recommendations?

0 Likes
Message 11 of 17

Stephane.kapetanovic
Mentor
Mentor

@HadiMoosavi 

Does your program itself handle synchronization across the six instances? If so, you could protect access to Robot with a lock. If not, it isn’t safe. It also depends on which parts are implemented. Your project is interesting, but what you’re trying to achieve is complex and not really within the scope of this forum, which is focused on the use of Robot software. I’m not saying there are no solutions, but you should carefully review the requirements of such an asynchronous architecture.

Best regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
Message 12 of 17

HadiMoosavi
Enthusiast
Enthusiast

It does manage the sync between instances. Although, I did not understand the part about protecting with a lock.
Could you expand on this?

0 Likes
Message 13 of 17

Stephane.kapetanovic
Mentor
Mentor

I was referring to a program you developed yourself and over which you have full control, not a third-party application you’re trying to integrate. In your case, it’s not safe.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/statements/lock

 

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
Message 14 of 17

WALIDGIO
Advocate
Advocate

Hi, Why my program always ask to run Robot analysis before starting my program that have robot API ?
Is there a solution to this problem, thank you

0 Likes
Message 15 of 17

Stephane.kapetanovic
Mentor
Mentor

hi @WALIDGIO 

that’s just how Robot works. There’s no real storage outside the open project, so if the app and project aren’t both running, a bunch of API calls just won’t work.

It’s kind of a built-in safeguard. Most people just add a check at the start of their script to catch that.

Sometimes it shows a message, sometimes it’s silent. You can also delay the check and handle it later in the flow if that makes more sense for your tool.

Some devs even build their own data formats or logic around Robot, so they can split things like, generate stuff first and deal with export later. That way, you are not stuck if Robot is used otherwise or not running permanently.

Excel works great for simple sequential workflows. If the data is more demanding, exporting to formats like plain text, CSV, JSON, XML, or even a database can give you more speed and flexibility.

Best regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes
Message 16 of 17

WALIDGIO
Advocate
Advocate

Hi @Stephane.kapetanovic,

 

Thanks for the explanation, that helped clarify things.

Quick question: I’d like my app to start even if Robot isn’t running. Then, later (e.g., on an "Import" button), I want to check if Robot and a project are available and proceed.

I want my C# app to:

  1. Start without requiring Robot

  2. Allow users to launch Robot later

  3. Recheck connection on "Import" without restarting the app

The problem is:
If I launch my app when Robot isn’t running, even setting robotApp = null, or trying robotApp = new RobotApplication()  when lunching Robot later doesn’t work. the app still acts like Robot is unavailable unless I restart the app.

Is there a clean way to reset or reinitialize the Robot connection once Robot is launched after the app has started?

Any tip or small example would be really appreciated!

Best,
Walid

0 Likes
Message 17 of 17

Stephane.kapetanovic
Mentor
Mentor

hi @WALIDGIO 

  1. Start without requiring Robot ->  yes but you can't use functions creating objects from servers

  2. Allow users to launch Robot later -> add a "send to robot" button

  3. Recheck connection on "Import" without restarting the app -> 1 2 3 asks to create your own objects and classes

Is there a clean way to reset or reinitialize the Robot connection once Robot is launched after the app has started? ReleaseComObject

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes